-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Fix .contains() does not mean it's a child #391
Fix .contains() does not mean it's a child #391
Conversation
🦋 Changeset detectedLatest commit: d4439c5 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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
4828f71
to
98948a0
Compare
@myieye This makes sense to me. Could you add an example of this use case (nested portal'd element) and run |
98948a0
to
dd9f77c
Compare
@techniq sorry, I jumped the gun on this one. But, I eventually nailed it down and added an example that breaks without my second commit. I also updated the PR description to explain exactly what was going wrong. |
0ed4ee4
to
0a4a8dc
Compare
@myieye I really appreciate the detailed write up and digging in. I've got 2 small asks :)
Thanks for all the effort here! |
@myieye Looks good! Ready to merge? |
@techniq Yes 👍 |
Thanks @myieye. Publishing as |
Three things were wrong here:
elem1.contains(elem2)
checks all descendants, so it doesn't imply that elem2 is a child of elem1onDestroy
was using the originaloptions
, which would be out of date if they had ever been changed (i.e. viaupdate()
)Due to a combination of these problems, when I navigate away from a route in my application I'm currently getting:
There are just so many little details that are wrong that it turns out there are a few ways to reproduce the bug, but what's crucial in my example is that:
{target: undefined}
so that inonDestroy
it queries for the nearest target..PortalTarget
) within the same{#if}
as the portal content. Otherwise,.contains()
will return false. The reason is that everything within the{#if}
gets pulled out of the DOM, so root elements in the{#if}
don't have aparentElement
, but the elements within that detached subtree are still conntected to each other.enabled: false
) or be in a different target that's also within the same{#if}
. So, in the example you can trigger the error whether or not you've clicked "Move to target".