Pure client based page complaining about `window is not defined` in solid-start (No SSR needed)
Back when I was just working with
solid.js
I could use window
in my code just fine, for. pages that are entirely client-rendered.
With solid-start
I use the solid-start-static
for client based pages, like described in Alex' blog post https://dev.to/lexlohr/using-solid-start-with-github-pages-3iok .
But this way I still get Error when evaluating SSR module: window is not defined
.
How can I tell solid-start
that I want a classic client-based SPA? (and no SSR needed)20 Replies
(similar for other client based global variables like
localStorage
).
Do I have to wrap all this in if (!isServer)
even though I never do SSr in this project?
Specifically, I use the aws-amplify
module for authentication with AWS Cognito, and internally it uses a bunch of global
,window
and localStorage
static adapter still does SSR,
it's a normal SSR in dev
and SSG at build
to disable SSR you do
{ ssr: false }
and then you don't need the static adapter, because you want only an empty .html file, not prerendered pages
But imo it's better to leave ssr on, and just make sure the pages are rendered only on the client
Then you can alvays opt-into SSR for some pages if you find the need, or at least SSR the app shell
when youre separating isomorphic components from client-only, make sure to use Suspense
+ lazy
to code-split and not load them on the server (tree-shaking doesn't work in dev)
sth like this: https://github.com/thetarnav/mxyz-mark/blob/master/apps/solid-web/src/routes.tsx#L44yup, it works at build time, I just wanted to see my code run with
yarn dev
.
The offending code sits in root.tsx
the auth-switch should happen before any route is accessible, therefore I guess I'll turn SSR off using { ssr: false }
i.e. regardless which route you load, if not signed in I show the signin-ui
I also have SSR rendered pages, but at the moment they sit in a different project on a different subdomain as the SPA
mhmm, when I do:
I still get
Uncaught ReferenceError: global is not defined
when fetching the site after running yarn dev
.
Where do you put the ssr: false
@thetarnav ?what is
global
?some global variable that browsers have that AWS amplify uses deep in its internals
well mine doesn't
I imported
aws amplify
the same way I used to in my other solid.js projects, where it just worked
only difference is that now I'm using solid-start
I'm not sure
is it still running on the server?
if you log something will you see it logged by vite server?
ah, it might be a polyfill problem, since AWS imported
buffer
and global
is a node thing
https://github.com/aws/aws-sdk-js/issues/2141
it's an ongoing issue
I remember now, you have to hack global into your index.html
It's a fix I have to add to all aws amplify projects and I forgot that I did that since with solid-js
I'm not using an index.html
anymore
same for all react projects using aws:
https://github.com/aws-amplify/amplify-js/issues/678
do we have a polyfills.ts
in solid-styart like react or angular have @thetarnav ?no idea
I'm not actually sure how to modify the .html file with ssr disabled since it's supposed to be generated either at build or request
let's close this one then and open a new more pertitant thread
https://discord.com/channels/722131463138705510/1113405856416014389/1113405856416014389
@thetarnav mhmm if you say the
.html
file is created, there must be some way of modyfing the code that creates the .html
to put this one-liner in there
first dumb approach was modying entry-client.tsx
with
(but that didn't work)
also tried editing node_modules/solid-start/entry-client/mount.tsx
but that doesn't really seem to affect the ouput of npm run dev
eitherUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
hey, so should be an
/dist/server/index.mjs
filein my case, for AWS, this is the code that runs server-side
the
client
part are the static assets that go into some kind of storage
the server part is the code that runs that generates the site
the index.html
is basically generated by node on the fly, it's not a static file that sits in a folderUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
in my case (for AWS Lambda), the
index.mjs
has a .handler
method, whose return value is a html response for an index.html
i think then you should use the static adapter, like in this tutorial https://dev.to/lexlohr/using-solid-start-with-github-pages-3iok
DEV Community
Using Solid Start with GitHub pages
You may or may not yet have heard about Solid Start, which is the much anticipated upcoming meta...
or, as I do too for a static page, just use
this folder looks very much like the
solid-start
default output, which is for node
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
good idea, I mean this one was solved anyway 🙂