pull/12335/head
Rich Harris 2 years ago
parent 2bfd5b22a8
commit a761d887f6

@ -1851,6 +1851,7 @@ export const template_visitors = {
); );
} else { } else {
context.state.init.push( context.state.init.push(
b.stmt(b.call('$.next')),
b.stmt( b.stmt(
(node.expression.type === 'CallExpression' ? b.call : b.maybe_call)( (node.expression.type === 'CallExpression' ? b.call : b.maybe_call)(
snippet_function, snippet_function,

@ -1187,9 +1187,9 @@ const template_visitors = {
return /** @type {import('estree').Expression} */ (context.visit(arg)); return /** @type {import('estree').Expression} */ (context.visit(arg));
}); });
if (node.metadata.dynamic && !context.state.skip_hydration_boundaries) { // if (!context.state.skip_hydration_boundaries) {
context.state.template.push(block_open); context.state.template.push(b.literal('<!--#-->'));
} // }
context.state.template.push( context.state.template.push(
b.stmt( b.stmt(
@ -1201,9 +1201,9 @@ const template_visitors = {
) )
); );
if (!context.state.skip_hydration_boundaries) { // if (!context.state.skip_hydration_boundaries) {
context.state.template.push(block_close); context.state.template.push(b.literal('<!--/-->'));
} // }
}, },
ClassDirective() { ClassDirective() {
throw new Error('Node should have been handled elsewhere'); throw new Error('Node should have been handled elsewhere');
@ -1368,11 +1368,12 @@ const template_visitors = {
each.push(b.let(node.index, index)); each.push(b.let(node.index, index));
} }
each.push(b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_OPEN)))); // TODO we shouldn't need these
each.push(b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--#each-item-->'))));
each.push(.../** @type {import('estree').BlockStatement} */ (context.visit(node.body)).body); each.push(.../** @type {import('estree').BlockStatement} */ (context.visit(node.body)).body);
each.push(b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_CLOSE)))); each.push(b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--/each-item-->'))));
const for_loop = b.for( const for_loop = b.for(
b.let(index, b.literal(0)), b.let(index, b.literal(0)),
@ -1382,14 +1383,14 @@ const template_visitors = {
); );
if (node.fallback) { if (node.fallback) {
const open = b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_OPEN))); const open = b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--#each-->')));
const fallback = /** @type {import('estree').BlockStatement} */ ( const fallback = /** @type {import('estree').BlockStatement} */ (
context.visit(node.fallback) context.visit(node.fallback)
); );
fallback.body.unshift( fallback.body.unshift(
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_OPEN_ELSE))) b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--#each!-->')))
); );
state.template.push( state.template.push(
@ -1398,10 +1399,10 @@ const template_visitors = {
b.block([open, for_loop]), b.block([open, for_loop]),
fallback fallback
), ),
block_close b.literal('<!--/each-->')
); );
} else { } else {
state.template.push(block_open, for_loop, block_open); state.template.push(b.literal('<!--#each-->'), for_loop, b.literal('<!--/each-->'));
} }
}, },
IfBlock(node, context) { IfBlock(node, context) {
@ -1416,14 +1417,14 @@ const template_visitors = {
: b.block([]); : b.block([]);
consequent.body.unshift( consequent.body.unshift(
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_OPEN))) b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--#if-->')))
); );
alternate.body.unshift( alternate.body.unshift(
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_OPEN_ELSE))) b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal('<!--#if!-->')))
); );
context.state.template.push(b.if(test, consequent, alternate), block_close); context.state.template.push(b.if(test, consequent, alternate), b.literal('<!--/if-->'));
}, },
AwaitBlock(node, context) { AwaitBlock(node, context) {
context.state.template.push( context.state.template.push(

@ -292,8 +292,7 @@ export function clean_nodes(
const is_text = trimmed.length === 1 && first.type === 'Text'; const is_text = trimmed.length === 1 && first.type === 'Text';
const is_anchored = const is_anchored = (is_dynamic_text || is_text) && parent.type === 'Fragment';
(is_dynamic_text || is_text) && (parent.type === 'Fragment' || parent.type === 'SnippetBlock');
return { hoisted, trimmed, is_standalone, is_anchored }; return { hoisted, trimmed, is_standalone, is_anchored };
} }

@ -182,7 +182,7 @@ export function each(anchor, flags, get_collection, get_key, render_fn, fallback
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
if ( if (
child_anchor.nodeType !== 8 || child_anchor.nodeType !== 8 ||
/** @type {Comment} */ (child_anchor).data !== HYDRATION_START /** @type {Comment} */ (child_anchor).data !== '#each-item'
) { ) {
// If `nodes` is null, then that means that the server rendered fewer items than what // If `nodes` is null, then that means that the server rendered fewer items than what
// expected, so break out and continue appending non-hydrated items // expected, so break out and continue appending non-hydrated items

@ -41,7 +41,7 @@ export function if_block(
let mismatch = false; let mismatch = false;
if (hydrating) { if (hydrating) {
const is_else = /** @type {Comment} */ (anchor).data === HYDRATION_START_ELSE; const is_else = /** @type {Comment} */ (anchor).data === '#if!';
if (condition === is_else) { if (condition === is_else) {
// Hydration mismatch: remove everything inside the anchor and start fresh. // Hydration mismatch: remove everything inside the anchor and start fresh.

@ -15,6 +15,7 @@ import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
* @returns {void} * @returns {void}
*/ */
export function snippet(anchor, get_snippet, ...args) { export function snippet(anchor, get_snippet, ...args) {
// console.log('snippet start', { anchor });
if (hydrating) { if (hydrating) {
hydrate_next(); hydrate_next();
} }
@ -40,6 +41,7 @@ export function snippet(anchor, get_snippet, ...args) {
if (hydrating) { if (hydrating) {
anchor = hydrate_node; anchor = hydrate_node;
// console.log('snippet end', { anchor });
} }
} }

@ -30,3 +30,9 @@ export function reset(node) {
hydrate_node = node; hydrate_node = node;
} }
} }
export function next() {
if (hydrating) {
hydrate_next();
}
}

@ -132,9 +132,9 @@ export function sibling(node, is_text = false) {
var type = next_sibling.nodeType; var type = next_sibling.nodeType;
if (type === 8 && /** @type {Comment} */ (next_sibling).data === HYDRATION_ANCHOR) { // if (type === 8 && /** @type {Comment} */ (next_sibling).data === HYDRATION_ANCHOR) {
return sibling(next_sibling, is_text); // return sibling(next_sibling, is_text);
} // }
// if a sibling {expression} is empty during SSR, there might be no // if a sibling {expression} is empty during SSR, there might be no
// text node to hydrate — we must therefore create one // text node to hydrate — we must therefore create one

@ -62,7 +62,7 @@ export {
bind_focused bind_focused
} from './dom/elements/bindings/universal.js'; } from './dom/elements/bindings/universal.js';
export { bind_window_scroll, bind_window_size } from './dom/elements/bindings/window.js'; export { bind_window_scroll, bind_window_size } from './dom/elements/bindings/window.js';
export { reset } from './dom/hydration.js'; export { next, reset } from './dom/hydration.js';
export { export {
once, once,
preventDefault, preventDefault,

Loading…
Cancel
Save