Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use remove instead of removeChild #2482

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

holynewbie
Copy link

removeChild may throw NotFoundError when the child was not a child of the node. So use the safe remove instead of removeChild

`removeChild` may throw NotFoundError when the child was not a child of the node.
Copy link

File size impact

Merging holynewbie-patch-1 into main will impact 2 files in 1 group.

browser (2/2)
File raw gzip brotli Event
dist/s.min.js -18 (7,889) -4 (3,129) -4 (2,841) modified
dist/system.min.js -18 (12,238) -8 (4,736) -1 (4,271) modified
Total size impact -36 (20,127) -12 (7,865) -5 (7,112)
node (0/1)

No impact on files in node group.

extras (0/8)

No impact on files in extras group.

Generated by file size impact during size-impact#8093285161

@guybedford
Copy link
Member

Since we inject the script into the head, it should always be a child of the head node. Did you really hit a case where this was not working correctly?

@holynewbie
Copy link
Author

holynewbie commented Mar 5, 2024

Since we inject the script into the head, it should always be a child of the head node. Did you really hit a case where this was not working correctly?

@guybedford Yes. I'm using a micro front-end framework garfish , when sandbox mode is enabled, it provides a fake document.

In some bad case, document.head does not contain the script created by system.js. This may be a bug in garfish,but I can't address it.

For robustness considerations, using remove instead of removeChild may avoid some bug like this👆

@guybedford
Copy link
Member

This is a bug in that sandbox implementation rather here if it is not behaving as expected by the HTML spec, so I don't think modifying SystemJS is the right place for the fix. Instead I'd recommend fixing the framework or using a local SystemJS patch.

@nilzona
Copy link
Contributor

nilzona commented Mar 11, 2024

To be fair, the proposed fix is more robust even if it is not a bug in SystemJS. If you have access to the script, then calling script.remove() will always work (probably :) ), whereas document.head.removeChild(script) may break if the the logic to where the script has been added changes. Maybe someone makes a scriptLoad hook and changes the script to be added as the last element of the body.

Does the fix risk breaking something else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants