You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, let me clarify what I want to do just to make sure no XY problems creep in: I want to make an app that can be built both as an SPA and Node server.
The Node version will connect to a pre-existing backend anonymously (serverside) and display data that way, with an option to log in as a user and get access to user specific data.
The SPA version will NOT have that anonymous option and will always require logging in, with the ability to select different backend hosts.
Both to make my job easier and to keep any user credentials far away from a potentially untrusted Node server (which isn't a realistic threat model but I'm sure some privacy nut out there would complain, considering the audience I'm building my app for) all authorized communication will be done in browser, with all user tokens being kept in browser, so any shortcomings of having loading screens and whatnot are not an issue for my use case.
But I've seem to hit a little snag in making this work: I'm not sure about which combination of SSR and prerendering options I need to pull this off correctly. Right now, my root +layout.ts has:
When I build as Node, everything's fine, but when I build as an SPA, it returns a "404 undefined" error UNTIL I try to click a link pointing to / which will then display the page the way I expect it to.
In the dev tools, I can see two 404'd fetches to http://0.0.0.0:8080/__data.json?x-sveltekit-invalidated=1 (and 100), and a console.log I put on there says the root layout has a data of, unsurprisingly, null (as there is no server to execute +layout.server.ts). The weird thing is, another console.log I put on the (app) root layout doesn't get triggered until I navigate to /. So whatever my issue is, it's happening at the very top +layout.server.ts, which for now reads a few cookies and doesn't do anything else. (And of course, I do check if LayoutData is null in the component itself.)
Does anyone here have any ideas on what may be causing this issue? I'm also attaching my SvelteKit config, just in case my error lies there. I haven't modified the Vite config in a way that seems relevant to this
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First of all, let me clarify what I want to do just to make sure no XY problems creep in: I want to make an app that can be built both as an SPA and Node server.
The Node version will connect to a pre-existing backend anonymously (serverside) and display data that way, with an option to log in as a user and get access to user specific data.
The SPA version will NOT have that anonymous option and will always require logging in, with the ability to select different backend hosts.
Both to make my job easier and to keep any user credentials far away from a potentially untrusted Node server (which isn't a realistic threat model but I'm sure some privacy nut out there would complain, considering the audience I'm building my app for) all authorized communication will be done in browser, with all user tokens being kept in browser, so any shortcomings of having loading screens and whatnot are not an issue for my use case.
But I've seem to hit a little snag in making this work: I'm not sure about which combination of SSR and prerendering options I need to pull this off correctly. Right now, my root
+layout.ts
has:And my
(app)
root layout (which is where most of the app routes will be in) has:When I build as Node, everything's fine, but when I build as an SPA, it returns a "404 undefined" error UNTIL I try to click a link pointing to
/
which will then display the page the way I expect it to.In the dev tools, I can see two 404'd fetches to
http://0.0.0.0:8080/__data.json?x-sveltekit-invalidated=1
(and 100), and aconsole.log
I put on there says the root layout has a data of, unsurprisingly,null
(as there is no server to execute+layout.server.ts
). The weird thing is, anotherconsole.log
I put on the(app)
root layout doesn't get triggered until I navigate to/
. So whatever my issue is, it's happening at the very top+layout.server.ts
, which for now reads a few cookies and doesn't do anything else. (And of course, I do check ifLayoutData
isnull
in the component itself.)Does anyone here have any ideas on what may be causing this issue? I'm also attaching my SvelteKit config, just in case my error lies there. I haven't modified the Vite config in a way that seems relevant to this
svelte.config.js.txt
Thanks in advance!
Edit: Here are my (pruned to just the relevant ones)
devDependencies
just in case:Beta Was this translation helpful? Give feedback.
All reactions