-
Notifications
You must be signed in to change notification settings - Fork 151
[Bug]: use:*
Directives Use Elements Whose ownerDocument
Differs from window.document
#278
Comments
use:*
Directives Use Elements Whose ownerDocument
Differs from window.document
use:*
Directives Use Elements Whose ownerDocument
Differs from window.document
Since the question was raised on Discord, it's also worth pointing out that elements created with const div = document.createElement("div");
console.assert(div.ownerDocument === document); // Succeeds Svelte's Actions are also able to recognize the correct |
Sidenote: Note sure if solidjs/solid#1740 is related since I didn't investigate the code. But if it touches |
I think this comes down to how elements are created as Solid isn't doing anything directly to mess with this. Until we can make a decision on |
See @ryansolid's comment in solidjs/solid#1936.
From some quick testing in the browser, it seems to me that nodes created with In any case, using If this doesn't get fixed/changed (depending on if it's seen as a bug), it might be worth pointing this out in the documentation. Not sure if it's too obscure/specific to mention, though. 🤷🏾♂️ |
Yeah I think it is because the elements are coming from template elements. I don't know what else would do it. We really aren't doing anything special. |
Yeah that seems to check out. In the browser: let template = document.createElement("template");
template.innerHTML = "<span>Hello</span>";
console.log(template.content.children[0].ownerDocument === document); // `false` I guess this isn't necessarily a bug in that case. 🤔 Though it might be unexpected behavior for devs coming from Svelte. (Not necessarily a bad thing.) |
Thanks for the update. Those Svelte Devs may be in for a surprise with Svelte 5 depending on timing of when they fire actions. They might fire them after connected. But Svelte 5 basically adopts Solid's render model. In terms of how to manage this. We might use |
The test actually _was not_ failing due to a bug in Vitest or Solid Testing Library. This test was actually (rightly) failing because of solidjs/solid-docs#278. This bug has been fixed by fdf61ed.
Describe the bug
The element passed to a
use:*
directive has anownerDocument
that differs from the application's Document (i.e.,window.document
) even though the element belongs to the application's Document. This prevents directives like the following from working:This discrepancy is problematic in certain types of Applications and NPM Packages related to the Web. It's not immediately clear what exactly
element.ownerDocument
is pointing to. It points to a Document, but it definitely doesn't point towindow.document
.Your Example Website or App
https://playground.solidjs.com/anonymous/5ddfcd3c-103f-4283-aff6-6720325bfbd5
Steps to Reproduce the Bug or Issue
element.ownerDocument
in the Solid Directive with the globalwindow.document
and find that the two are not referentially equivalentThe Solid.js Playground Link provided above exemplifies this problem.
Expected behavior
The
HTMLElement
passed to any given Solid Directive on the Web should have anownerDocument
that's [referentially] equivalent to the application's Document (i.e.,window.document
).Platform
Additional context
This bug is not observable after the application has finished rendering. If you open the devtools and select the element that was given a directive, then
element.ownerDocument === window.document
will yieldtrue
in theconsole
even though it yieldedfalse
during the call to the Solid Directive.The text was updated successfully, but these errors were encountered: