[@emotion/sheet] Prevent stale before element references#3364
Open
tkajtoch wants to merge 2 commits intoemotion-js:mainfrom
Open
[@emotion/sheet] Prevent stale before element references#3364tkajtoch wants to merge 2 commits intoemotion-js:mainfrom
before element references#3364tkajtoch wants to merge 2 commits intoemotion-js:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 87aa1ef The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Author
|
dtslint CI is failing due to TypeScript 6.0 deprecation errors unrelated to changes made in this PR. |
Author
|
@Andarist would you be able to take a look at this or assign another maintainer please? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
This PR fixes a bug in
@emotion/sheetthat causes aNotFoundErrorto be thrown when a stale (removed, moved, disconnected, or otherwise not a child of thecontainer) element is set in thebeforeproperty.This can happen internally and externally. We noticed it breaking when multiple
@emotion/react's<Global />components are being reinserted into the same container, but it can be caused by anything that controls thebeforeproperty from the outside (which is technically how that property is supposed to be used).Why:
To prevent
@emotion/sheetfrom crashing user applications.How:
A stale element reference can happen in many ways. Since
beforeis externally controllable, we have to check whether it references an expected element and is up to date. I do it by confirming it's a child of thecontainerelement, which should be good enough to prevent this issue.All other conditions within
_insertTagseem to reference the actual state of the DOM, which is safe considering its synchronous nature.Checklist: