Closed jimafisk closed 3 years ago
Tried rewriting slightly differently but it has the same issue:
Per https://svelte.dev/tutorial/onmount
lifecycle functions don't run during SSR, which means we can avoid fetching data that should be loaded lazily once the component has been mounted in the DOM
Edit: You don't need onMount
in the snippet above ^, but the rewritten code still doesn't work in the static html:
It would be nice to eventually update the build script with https://github.com/sveltejs/svelte/issues/958
I took a look at https://github.com/sveltejs/svelte/pull/5476
This creates an array of filenames of components that were rendered during SSR called renderedComponents
. We would have to update cmd/build/data_source.go
to return this in v8go in this manner:
const { head, html, css, renderedComponents } = App.render({
answer: 42
});
An earlier attempt at this feature has some details about use:
const { js } = //get test component, and apply custom filename option: compile(string, { filename: 'test' }
let Component = //turn JS into component
const { renderedComponents} = Component.render();
if(renderedComponents[0] !== 'test'){
//fail test
}
Since we're compiling all the components manually in cmd/build/client.go
we might be able to just leverage that to accomplish the same thing.
Related:
This should be working now using the allComponents
prop introduced in v0.3.2
.
I added some info about how to use this in a blog post in the default starter, but you can find more details in the docs here: https://plenti.co/docs/allComponents
Working link to docs: https://plenti.co/docs/allcomponents/
The allComponents
prop is now allLayouts
: https://plenti.co/docs/alllayouts
The default starter now includes a content driven component example inspired by https://github.com/plentico/plenti/issues/9.
This works well once the page hydrates, but the fallback HTML shows
undefined
instead of the component.