Merge pull request #677 from sveltejs/gh-664

add dev mode hydration error
pull/683/head
Rich Harris 8 years ago committed by GitHub
commit d237983374

@ -247,6 +247,7 @@ export default function dom(
nodes.forEach( ${generator.helper('detachNode')} ); nodes.forEach( ${generator.helper('detachNode')} );
` : ` :
deindent` 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.create();
`} `}
this._fragment.${block.hasIntroMethod ? 'intro' : 'mount'}( options.target, null ); this._fragment.${block.hasIntroMethod ? 'intro' : 'mount'}( options.target, null );

@ -230,4 +230,23 @@ describe("runtime", () => {
new SvelteComponent(); new SvelteComponent();
}, /'target' is a required option/); }, /'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