Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/docs-ref-document-timing.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion documentation/solid-2.0/07-dom.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ let el;
<div ref={[node => (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)

Expand Down
2 changes: 1 addition & 1 deletion packages/solid/CHEATSHEET.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ hydrate(() => <App />, document.getElementById("root")!);
<button ref={[autofocus, tooltip({ content: "Save" })]} />
```

A ref runs before the element is attached: `el.isConnected` is `false` and `el.ownerDocument.defaultView` is `null`. Use the global `window`/`document`, or do layout-dependent work in `onSettled`.
A ref runs before the element is attached: `el.isConnected` is `false`, and unless its template contains a custom element, `el.ownerDocument.defaultView` is `null`. Use the global `window`/`document`, or do layout-dependent work in `onSettled`.

Two-phase directive (recommended):

Expand Down
Loading