From fe27e492a0f1d0feacd090a5f7e7ec43abd74b2b Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Oct 2026 16:04:10 +0530 Subject: [PATCH] docs: narrow the ref-timing note to templates without custom elements --- .changeset/docs-ref-document-timing.md | 5 +++++ documentation/solid-2.0/07-dom.md | 2 +- packages/solid/CHEATSHEET.md | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/docs-ref-document-timing.md diff --git a/.changeset/docs-ref-document-timing.md b/.changeset/docs-ref-document-timing.md new file mode 100644 index 000000000..2e67897ae --- /dev/null +++ b/.changeset/docs-ref-document-timing.md @@ -0,0 +1,5 @@ +--- +"solid-js": patch +--- + +The DOM docs and cheatsheet narrow the ref-timing note: inside a ref, `el.ownerDocument.defaultView` is `null` only when the element's template contains no custom element; a template with one is imported into the live document as a whole. diff --git a/documentation/solid-2.0/07-dom.md b/documentation/solid-2.0/07-dom.md index c0108fdfe..bdd88a7c6 100644 --- a/documentation/solid-2.0/07-dom.md +++ b/documentation/solid-2.0/07-dom.md @@ -93,7 +93,7 @@ let el;
(el = node), autofocus]} />; // assigned ``` -A ref runs before the element is inserted into the page. At that point `el.isConnected` is `false`, and `el.ownerDocument` is the inert document of the template the element was cloned from, so `el.ownerDocument.defaultView` is `null`. Don't reach the window or document through the element inside a ref: use the global `window`/`document`, or do work that needs the attached element (measuring, reading computed styles) in `onSettled`. +A ref runs before the element is inserted into the page, so `el.isConnected` is `false`. Its document depends on the rest of the template: an element cloned from a template with no custom element still belongs to that template's inert document, so `el.ownerDocument.defaultView` is `null`, while a template containing a custom element is imported into the live document as a whole. Don't reach the window or document through the element inside a ref: use the global `window`/`document`, or do work that needs the attached element (measuring, reading computed styles) in `onSettled`. #### Two-phase directive factories (owned setup, unowned application) diff --git a/packages/solid/CHEATSHEET.md b/packages/solid/CHEATSHEET.md index 62d74231b..b74fe2678 100644 --- a/packages/solid/CHEATSHEET.md +++ b/packages/solid/CHEATSHEET.md @@ -473,7 +473,7 @@ hydrate(() => , document.getElementById("root")!);