add dev mode hydration error (closes #664)

pull/677/head
Rich Harris 8 years ago
parent ee5a60fd71
commit 7eb4f2d1c0

@ -247,6 +247,7 @@ export default function dom(
nodes.forEach( ${generator.helper('detachNode')} );
` :
deindent`
${options.dev && `if ( options.hydrate ) throw new Error( 'options.hydrate only works if the component was compiled with the \`hydratable: true\` option' );`}
this._fragment.create();
`}
this._fragment.${block.hasIntroMethod ? 'intro' : 'mount'}( options.target, null );

@ -230,4 +230,23 @@ describe("runtime", () => {
new SvelteComponent();
}, /'target' is a required option/);
});
it("fails if options.hydrate is true but the component is non-hydratable", () => {
const { code } = svelte.compile(`<div></div>`, {
format: "iife",
name: "SvelteComponent",
dev: true
});
const SvelteComponent = eval(
`(function () { ${code}; return SvelteComponent; }())`
);
assert.throws(() => {
new SvelteComponent({
target: {},
hydrate: true
});
}, /options.hydrate only works if the component was compiled with the `hydratable: true` option/);
});
});

Loading…
Cancel
Save