Skip to content

Commit

Permalink
Make hydratable (#65).
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed Sep 21, 2020
1 parent 8a19a8e commit 6057b14
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/build/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func compileSvelte(ctx *v8go.Context, SSRctx *v8go.Context, layoutPath string, d
componentStr := string(component)

// Compile component with Svelte.
ctx.RunScript("var { js, css } = svelte.compile(`"+componentStr+"`, {css: false});", "compile_svelte")
ctx.RunScript("var { js, css } = svelte.compile(`"+componentStr+"`, {css: false, hydratable: true});", "compile_svelte")

// Get the JS code from the compiled result.
jsCode, err := ctx.RunScript("js.code;", "compile_svelte")
Expand Down
12 changes: 4 additions & 8 deletions ejected/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Router from './router.svelte';

const replaceContainer = Component => {
const frag = document.createDocumentFragment();
const dom = document.querySelector('#hydrate-plenti');
const component = new Component( Object.assign( {}, { target: dom }, { target: frag } ));
dom.replaceWith(frag);
}

replaceContainer(Router);
new Router({
target: document.querySelector('#hydrate-plenti'),
hydrate: true
});
12 changes: 4 additions & 8 deletions generated/ejected.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,10 @@ staticBuildStr.forEach(arg => {
});`),
"/main.js": []byte(`import Router from './router.svelte';
const replaceContainer = Component => {
const frag = document.createDocumentFragment();
const dom = document.querySelector('#hydrate-plenti');
const component = new Component( Object.assign( {}, { target: dom }, { target: frag } ));
dom.replaceWith(frag);
}
replaceContainer(Router);`),
new Router({
target: document.querySelector('#hydrate-plenti'),
hydrate: true
});`),
"/router.svelte": []byte(`<Html {route} {content} {allContent} />
<script>
Expand Down

0 comments on commit 6057b14

Please sign in to comment.