error sooner

pull/15851/head
Rich Harris 4 months ago
parent 03f1661176
commit 84305cf2a9

@ -12,6 +12,7 @@ import {
hydrate_next,
hydrate_node,
hydrating,
read_hydration_instruction,
remove_nodes,
set_hydrate_node,
set_hydrating
@ -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

@ -4,6 +4,7 @@ import {
hydrate_next,
hydrate_node,
hydrating,
read_hydration_instruction,
remove_nodes,
set_hydrate_node,
set_hydrating
@ -56,8 +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;
if (!data) return;
const data = read_hydration_instruction(anchor);
if (data === HYDRATION_START) {
hydrate_index = 0;
} else if (data === HYDRATION_START_ELSE) {

@ -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;
}

Loading…
Cancel
Save