Skip to content

Commit

Permalink
Merge pull request #677 from sveltejs/gh-664
Browse files Browse the repository at this point in the history
add dev mode hydration error
  • Loading branch information
Rich-Harris authored Jun 25, 2017
2 parents ee5a60f + 7eb4f2d commit d237983
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/generators/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
19 changes: 19 additions & 0 deletions test/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});

0 comments on commit d237983

Please sign in to comment.