From beff4651074bb0bb5fdd55ec7b0e7fb9eb523217 Mon Sep 17 00:00:00 2001 From: Hunor Karaman Date: Thu, 21 Feb 2019 07:21:52 +0100 Subject: [PATCH 1/2] added state.site.preloaded for server-side rendering --- lib/adapters/choo.js | 5 ++++- readme.md | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/adapters/choo.js b/lib/adapters/choo.js index fbf4689..4280786 100644 --- a/lib/adapters/choo.js +++ b/lib/adapters/choo.js @@ -21,8 +21,11 @@ function plugin (parent, options) { state.events.CONTENT_LOAD = 'content:load' // listeners - emitter.on(state.events.DOMCONTENTLOADED, contentLoad) emitter.on(state.events.CONTENT_LOAD, contentLoad) + // only load the content if it wasn't rehydrated by the server + if (!state.site.preloaded) { + emitter.on(state.events.DOMCONTENTLOADED, contentLoad) + } /** * primary method diff --git a/readme.md b/readme.md index dd56025..d59a462 100644 --- a/readme.md +++ b/readme.md @@ -63,7 +63,7 @@ function view (state, emit) { ` } } -``` +``` @@ -161,4 +161,4 @@ For specifics on formatting directories and files, take a look at the dependenci ## Contributing -Enoki is early in development. If you’d like to see support for webpack, or whatever other tooling, feel free to contribute! \ No newline at end of file +Enoki is early in development. If you’d like to see support for webpack, or whatever other tooling, feel free to contribute! From 606c5e109c2c008d156c72d1eba2710879f5f852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?hunor=20karam=C3=A1n?= Date: Thu, 21 Feb 2019 07:43:23 +0100 Subject: [PATCH 2/2] use loaded instead --- lib/adapters/choo.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/adapters/choo.js b/lib/adapters/choo.js index 4280786..a7b1ea3 100644 --- a/lib/adapters/choo.js +++ b/lib/adapters/choo.js @@ -12,6 +12,9 @@ function plugin (parent, options) { // content state state.site = state.site || { loaded: false, p2p: false } state.content = state.content || { } + + // check if the content was preloaded + state.site.loaded = state.site.preloaded === true // nanopage state.page = new Page(state) @@ -23,7 +26,7 @@ function plugin (parent, options) { // listeners emitter.on(state.events.CONTENT_LOAD, contentLoad) // only load the content if it wasn't rehydrated by the server - if (!state.site.preloaded) { + if (!state.site.loaded) { emitter.on(state.events.DOMCONTENTLOADED, contentLoad) }