Skip to content

Replace removeChild with remove #213465

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

Merged
merged 3 commits into from
Jun 4, 2024

Conversation

remcohaszing
Copy link
Contributor

This replaces most uses of parent.removeChild(child) with child.remove().

The two are almost equivalent. The only difference is that parent.removeChild(child) throws if the given node is not a child of the parent, whereas child.remove() never throws. There is no noticable performance difference. The only reason to use removeChild is to support Internet Explorer, but that’s no longer supported by Monaco editor.

I tested this in the Monaco playground, but not very thoroughly.

@remcohaszing remcohaszing force-pushed the remove-child-remove branch 2 times, most recently from 911d359 to 5cf9f14 Compare May 25, 2024 15:24
This replaces most uses of `parent.removeChild(child)` with
`child.remove()`.

The two are almost equivalent. The only difference is that
`parent.removeChild(child)` throws if the given node is not a child of
the parent, whereas `child.remove()` never throws. There is no noticable
performance difference. The only reason to use `removeChild` is to
support Internet Explorer, but that’s no longer supported by Monaco
editor.
The script content changed, so the sha256 hash changed too.
@remcohaszing remcohaszing force-pushed the remove-child-remove branch from 6d51dfb to 277b6e2 Compare June 4, 2024 14:04
Co-authored-by: Logan Ramos <lramos15@gmail.com>
Copy link
Member

@lramos15 lramos15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the information and the contribution

@lramos15 lramos15 enabled auto-merge (squash) June 4, 2024 20:14
@lramos15 lramos15 added this to the June 2024 milestone Jun 4, 2024
@@ -5,7 +5,7 @@
<meta charset="UTF-8">

<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; script-src 'sha256-bQPwjO6bLiyf6v9eDVtAI67LrfonA1w49aFkRXBy4/g=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">
content="default-src 'none'; script-src 'sha256-noHVLQsurkONXmA3fcuAmcZ8UPYm/db88mhm9gAXcvk=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjbvz is this change expected?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, it matches what I computed for the <script> tag at https://emn178.github.io/online-tools/sha256.html

image

@lramos15 lramos15 merged commit a131a88 into microsoft:main Jun 4, 2024
6 checks passed
@remcohaszing remcohaszing deleted the remove-child-remove branch June 5, 2024 06:07
bpasero added a commit that referenced this pull request Jun 5, 2024
@bpasero
Copy link
Member

bpasero commented Jun 5, 2024

@remcohaszing @lramos15 isnt this a bad change? Notice 4 remove calls after, and 2 before?

image

Did we review this change throughly?

@remcohaszing
Copy link
Contributor Author

remcohaszing commented Jun 5, 2024

Yes, you just beat me to this comment. It’s a sloppy mistake. It happens twice, right before and after that else keyword.

Do you want to go through with the full revert or should I just fix those occurrences?

bpasero added a commit that referenced this pull request Jun 5, 2024
remcohaszing added a commit to remcohaszing/vscode that referenced this pull request Jun 5, 2024
This fixes a regression caused by microsoft#213465

Closes microsoft#214303
Closes microsoft#214345
if (defaultStyles.length) {
mainWindow.document.head.removeChild(defaultStyles[0]);
}
defaultStyles?.[0].remove();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@remcohaszing this is not a good change, what if the array is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was indeed wrong. Fixed it in #214348.

catch (error) {
// Ignore, removed already by change of focus
}
this.selectDropDownContainer.remove(); // remove to take out the CSS rules we add
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this throw? why was it try/catch before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. parent.removeChild(child) throws if child is not a child of parent. child.remove() never throws. Aside from not needing a reference to the parent, that’s the only difference.

remcohaszing added a commit to remcohaszing/vscode that referenced this pull request Jun 5, 2024
bpasero added a commit that referenced this pull request Jun 5, 2024
* Fix opening select boxes

This fixes a regression caused by #213465

Closes #214303
Closes #214345

* Fix another regression caused by #213465

---------

Co-authored-by: Benjamin Pasero <benjamin.pasero@microsoft.com>
@ghost ghost mentioned this pull request Jul 7, 2024
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Jul 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants