Commit af3f30d
fix: warn instead of crash on invalid HTML nesting around islands (#3762)
## Summary
- When a block-level element (e.g. `<div>`) is placed inside an inline
element (e.g. `<p>`) that wraps an island, the browser fixes the invalid
nesting by splitting the parent, moving Fresh's comment markers into
different DOM nodes
- Previously this caused a fatal `DOMException` during hydration,
crashing all client-side JS on the page
- Now Fresh detects that `start.parentNode !== end.parentNode` before
calling `createRootFragment`, logs a descriptive error message
explaining the invalid nesting, and skips the broken island instead of
crashing
Example of the error message:
```
Fresh hydration error: the island "BugIsland" has invalid HTML nesting.
Its start and end markers were reparented by the browser into different
DOM nodes. This is usually caused by placing a block-level element
(like <div>) inside an inline element (like <p> or <span>). Check the
HTML around this island for invalid nesting.
```
Closes #2121
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 07878fc commit af3f30d
3 files changed
Lines changed: 73 additions & 2 deletions
File tree
- packages/fresh
- src/runtime/client
- tests
- fixtures_islands
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
167 | 190 | | |
168 | 191 | | |
169 | 192 | | |
170 | 193 | | |
171 | | - | |
| 194 | + | |
172 | 195 | | |
173 | 196 | | |
174 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
802 | 803 | | |
803 | 804 | | |
804 | 805 | | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
0 commit comments