From 6057b14ce670293b500dac853a1bcca270f4ae66 Mon Sep 17 00:00:00 2001
From: jimafisk
Date: Mon, 21 Sep 2020 17:33:38 -0400
Subject: [PATCH] Make hydratable (#65).
---
cmd/build/client.go | 2 +-
ejected/main.js | 12 ++++--------
generated/ejected.go | 12 ++++--------
3 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/cmd/build/client.go b/cmd/build/client.go
index 3dbf00f0..adc75858 100644
--- a/cmd/build/client.go
+++ b/cmd/build/client.go
@@ -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")
diff --git a/ejected/main.js b/ejected/main.js
index 0509f5dd..cc569050 100755
--- a/ejected/main.js
+++ b/ejected/main.js
@@ -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);
\ No newline at end of file
+new Router({
+ target: document.querySelector('#hydrate-plenti'),
+ hydrate: true
+});
\ No newline at end of file
diff --git a/generated/ejected.go b/generated/ejected.go
index 6c44cdd4..3526ff88 100644
--- a/generated/ejected.go
+++ b/generated/ejected.go
@@ -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(`