blockless
Rich Harris 2 years ago
parent 0085226ab1
commit 0f9256e20e

@ -7,22 +7,6 @@ import {
} from './constants.js'; } from './constants.js';
import { current_block } from './runtime.js'; import { current_block } from './runtime.js';
/** @returns {import('./types.js').HeadBlock} */
export function create_head_block() {
return {
// dom
d: null,
// effect
e: null,
// parent
p: /** @type {import('./types.js').Block} */ (current_block),
// transition
r: null,
// type
t: HEAD_BLOCK
};
}
/** @returns {import('./types.js').DynamicElementBlock} */ /** @returns {import('./types.js').DynamicElementBlock} */
export function create_dynamic_element_block() { export function create_dynamic_element_block() {
return { return {

@ -10,7 +10,7 @@ import {
map_set, map_set,
set_class_name set_class_name
} from './operations.js'; } from './operations.js';
import { create_dynamic_element_block, create_head_block, create_snippet_block } from './block.js'; import { create_dynamic_element_block, create_snippet_block } from './block.js';
import { import {
PassiveDelegatedEvents, PassiveDelegatedEvents,
DelegatedEvents, DelegatedEvents,
@ -1481,49 +1481,34 @@ export function slot(anchor_node, slot_fn, slot_props, fallback_fn) {
} }
/** /**
* @param {(anchor: Node | null) => void} render_fn * @param {(anchor: Node | null) => void} fn
* @returns {void} * @returns {void}
*/ */
export function head(render_fn) { export function head(fn) {
const block = create_head_block();
// The head function may be called after the first hydration pass and ssr comment nodes may still be present, // The head function may be called after the first hydration pass and ssr comment nodes may still be present,
// therefore we need to skip that when we detect that we're not in hydration mode. // therefore we need to skip that when we detect that we're not in hydration mode.
let hydration_fragment = null; let hydration_fragment = null;
let previous_hydration_fragment = null; let previous_hydration_fragment = null;
let is_hydrating = hydrating;
if (is_hydrating) { if (hydrating) {
hydration_fragment = get_hydration_fragment(document.head.firstChild); hydration_fragment = get_hydration_fragment(document.head.firstChild);
previous_hydration_fragment = current_hydration_fragment; previous_hydration_fragment = current_hydration_fragment;
set_current_hydration_fragment(hydration_fragment); set_current_hydration_fragment(hydration_fragment);
} }
try { try {
const head_effect = render_effect( render_effect(() => {
() => { let anchor = null;
const current = block.d;
if (current !== null) { if (!hydrating) {
remove(current); anchor = empty();
block.d = null; document.head.appendChild(anchor);
}
let anchor = null;
if (!hydrating) {
anchor = empty();
document.head.appendChild(anchor);
}
render_fn(anchor);
},
block,
false
);
push_destroy_fn(head_effect, () => {
const current = block.d;
if (current !== null) {
remove(current);
} }
fn(anchor);
}); });
block.e = head_effect;
} finally { } finally {
if (is_hydrating) { if (hydrating) {
set_current_hydration_fragment(previous_hydration_fragment); set_current_hydration_fragment(previous_hydration_fragment);
} }
} }

Loading…
Cancel
Save