Comments (4)
Here's a gif of the example above working once that export statement is adjusted:
from plenti.
Adding the regex for export statements seems to get this working for me locally. Even though it's working functionally in the browser, the build still shows the following errors:
Could not add SSR Component: ReferenceError: writable is not defined
Can't render htmlComponent: TypeError: Cannot read property 'subscribe' of undefined
This is being thrown at the bottom of cmd/build/client.go
when passed the following updated ssrStr
:
/* generated by Svelte v3.23.2 */
/*import { create_ssr_component } from "svelte/internal";*/
/*import { writable } from "svelte/store";*/
var layout_scripts_stores_svelte = writable(0);
var layout_scripts_stores_svelte_NOT_USED = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
return ``;
});
/*export default Component;*/
/*export { layout_scripts_stores_svelte };*/
We need to add the writable()
function from node_modules/svelte/store/index.mjs
to the v8go ctx. This brings up a larger point about how we're not actually trying to import these libraries at all, we need svelte/store in this case but we could need others. We also only want to import the libraries we need specifically for the current project to avoid bloat.
from plenti.
I was perplexed how the SSR component could fail to be added to the ctx yet still work and be available at public/spa/scripts/stores.js
. Then I remembered adding the SSR component to the ctx is only needed to render html. Since this is a script component that doesn't actually create any markup, it's ok to skip this part entirely - the same goes for any script component. The public/spa/scripts/stores.js
output is created during the client rendering that happens earlier.
We may be able speed things up marginally (and avoid similar errors) but excluding script only files from the SSR rendering. I don't want to hardcode looking for files in layout/scripts
because I want that directory structure to be flexible to the user. A better approach is probably to look for and empty return statement from create_ssr_component()
and skip adding it to the ctx if that's the case.
from plenti.
I take it back, we'll still need to add scripts to ctx to keep things like titles working with static html. Also the index page doesn't SSR with the reference to ../scripts/stores.svelte
if we don't.
It might be easiest to just add all svelte libraries to the SSR ctx:
- animate
- easing
- internal (* already added)
- motion
- store
- transition
This is only used for SSR-ing to create static HTML so won't add bloat to the created site. Reading the node_module files and loading the libraries will slow the build though.
from plenti.
Related Issues (20)
- Schema bleed HOT 2
- Gitea backend for CMS HOT 2
- Check port before build
- [Feature Request] Make plenti a caddy plugin HOT 2
- Unable to launch CMS on localhost HOT 7
- Hydration flicker HOT 1
- Bitbucket CMS Backend
- Can't use hyphens in filename HOT 1
- Install in Ubuntu HOT 1
- Failing build: Credentials are no longer valid for the Snap Store HOT 4
- Assets dir in Plenti site template HOT 3
- Failed build: field replacements not found in type config.Archive HOT 4
- Can SSR be enabled with V8 engine? HOT 2
- Error when using CMS editor with GitLab Pages in a monorepo HOT 5
- plenti serve is spitting errors HOT 9
- Fingerprint SPA to bust cache HOT 1
- Can't use "plenti" command HOT 2
- Broken build: invalid go version '1.21.0': must match format 1.23 HOT 1
- Component cache
- Custom env variable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plenti.