fix treeshaking

pull/10798/head
Rich Harris 2 years ago
parent 818dace66e
commit b2ca97171f

@ -11,3 +11,5 @@
/motion.d.ts /motion.d.ts
/store.d.ts /store.d.ts
/transition.d.ts /transition.d.ts
/scripts/_bundle.js

@ -74,7 +74,7 @@ for (const key in pkg.exports) {
} }
const client_main = path.resolve(pkg.exports['.'].browser); const client_main = path.resolve(pkg.exports['.'].browser);
const without_hydration = await bundle_code( const bundle = await bundle_code(
// Use all features which contain hydration code to ensure it's treeshakeable // Use all features which contain hydration code to ensure it's treeshakeable
compile( compile(
` `
@ -109,15 +109,17 @@ const without_hydration = await bundle_code(
).js.code ).js.code
); );
if (!without_hydration.includes('current_hydration_fragment')) { if (!bundle.includes('current_hydration_fragment')) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(`✅ Hydration code treeshakeable`); console.error(`✅ Hydration code treeshakeable`);
} else { } else {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(without_hydration); console.error(bundle);
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(`❌ Hydration code not treeshakeable`); console.error(`❌ Hydration code not treeshakeable`);
failed = true; failed = true;
fs.writeFileSync('scripts/_bundle.js', bundle);
} }
// eslint-disable-next-line no-console // eslint-disable-next-line no-console

@ -41,9 +41,6 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn,
hydrate_block_anchor(anchor_node); hydrate_block_anchor(anchor_node);
/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
let mismatch = false;
/** @type {null | import('#client').TemplateNode | Array<import('#client').TemplateNode>} */ /** @type {null | import('#client').TemplateNode | Array<import('#client').TemplateNode>} */
let consequent_dom = null; let consequent_dom = null;
@ -62,6 +59,9 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn,
const if_effect = render_effect(() => { const if_effect = render_effect(() => {
if (condition === (condition = !!condition_fn())) return; if (condition === (condition = !!condition_fn())) return;
/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
let mismatch = false;
if (hydrating) { if (hydrating) {
const comment_text = /** @type {Comment} */ (current_hydration_fragment?.[0])?.data; const comment_text = /** @type {Comment} */ (current_hydration_fragment?.[0])?.data;
@ -154,8 +154,6 @@ export function if_block(anchor_node, condition_fn, consequent_fn, alternate_fn,
if_effect.f |= IS_ELSEIF; if_effect.f |= IS_ELSEIF;
} }
mismatch = false; // TODO not sure if we actually need this — belt and braces
if_effect.ondestroy = () => { if_effect.ondestroy = () => {
// TODO make this unnecessary by linking the dom to the effect, // TODO make this unnecessary by linking the dom to the effect,
// and removing automatically on teardown // and removing automatically on teardown

Loading…
Cancel
Save