10000 fix: update_branch with (anchor).data possible undefined on ios devices by matteobattista · Pull Request #15851 · sveltejs/svelte · GitHub
[go: up one dir, main page]

Skip to content

fix: update_branch with (anchor).data possible undefined on ios devices #15851

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

Merged
merged 4 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension < 8000 label class="SelectMenu-item" role="menuitem"> .md  (1)

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/silly-apples-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: handle more hydration mismatches
3 changes: 2 additions & 1 deletion packages/svelte/src/internal/client/dom/blocks/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
hydrate_next,
hydrate_node,
hydrating,
read_hydration_instruction,
remove_nodes,
set_hydrate_node,
set_hydrating
Expand Down Expand Up @@ -160,7 +161,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
let mismatch = false;

if (hydrating) {
var is_else = /** @type {Comment} */ (anchor).data === HYDRATION_START_ELSE;
var is_else = read_hydration_instruction(anchor) === HYDRATION_START_ELSE;

if (is_else !== (length === 0)) {
// hydration mismatch — remove the server-rendered DOM and start over
Expand Down
4 changes: 3 additions & 1 deletion packages/svelte/src/internal/client/dom/blocks/if.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
hydrate_next,
hydrate_node,
hydrating,
read_hydration_instruction,
remove_nodes,
set_hydrate_node,
set_hydrating
Expand Down Expand Up @@ -56,7 +57,8 @@ export function if_block(node, fn, [root_index, hydrate_index] = [0, 0]) {

if (hydrating && hydrate_index !== -1) {
if (root_index === 0) {
const data = /** @type {Comment} */ (anchor).data;
const data = read_hydration_instruction(anchor);

if (data === HYDRATION_START) {
hydrate_index = 0;
} else if (data === HYDRATION_START_ELSE) {
Expand Down
13 changes: 13 additions & 0 deletions packages/svelte/src/internal/client/dom/hydration.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,16 @@ export function remove_nodes() {
node = next;
}
}

/**
*
* @param {TemplateNode} node
*/
export function read_hydration_instruction(node) {
if (!node || node.nodeType !== 8) {
w.hydration_mismatch();
throw HYDRATION_ERROR;
}

return /** @type {Comment} */ (node).data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test } from '../../test';

// https://github.com/sveltejs/svelte/issues/15819
export default test({
expect_hydration_error: true
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>start</p><p>cond</p><!---->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!--[--> <p>start</p><!--[--><p>cond</p><!--]--><!--]-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
const cond = true;
</script>

<p>start& 6D4E lt;/p>{#if cond}<p>cond</p>{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test } from '../../test';

// https://github.com/sveltejs/svelte/issues/15819
export default test({
expect_hydration_error: true
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>start</p> pre123 mid<!---->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!--[--><p>start</p>pre<a>123</a> <!--[-->mid<!--]--><!--]-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
let cond = true;
</script>

<p>start</p>
pre123
{#if cond}
mid
{/if}
0