-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adapter-static has issues with server endpoints #7183
Comments
This happens with the skeleton project as well, with just adding adapter static. |
I get this with a project with no dynamic routes and just a single |
Same same, happens everywhere and it does not take in account any |
To clarify: you want to make SvelteKit ignore the endpoints, because after deployment there's an API at the given URL?
This is expected. You need to add
This needs more info. Also, |
The thing is that I have prerender=true in root +layout.js and my +server.js only has a |
That's what I was thinking (first comment). The endpoint in local development is super convenient. Without that I think I'd either have to prefix all my API calls and probably deal with CORS, or else put a proxy in front and split traffic between dev Vite and my real API. Isn't the idea of prerendering an endpoint sort of nonsensical? Instead of saying "the fact that nonsensical to prerender things exist, you can't use adapter-static" I'm just wondering if it makes more sense to ignore the nonsensical to prerender things. |
I'm lost. You have pages with dynamic data, but you're trying to prerender them? |
In my case I am trying not to prerender then but i either get the message with prerender false, that it encouraged dynamic route and I should try setting layout prerender true, but if I set it to true, it says it wont prerender it. So either I've missed something in docs or there is some bugs. Or maybe I am completely missing the point, but with whatever setting, I cant buils with adapter static. Ive set global +layout.js with prerender true, and tried to set dynamic routes with prerender false. In all honesty I've tried all combinations, and I just can't build with static adapter. |
You can't use adapter static and use dynamic endpoints. There is no server running on the backend, so there is nothing that can serve that GET request. You need to use a different adapter for that. @johnnysprinkles case is different, he wants that endpoint only during dev mode but ignore it when building. |
Well my case is similar, I have 2 environments, one uses node adapter and that node environment builds production with adapter static. So yeah i want to use dynamic ones for node env, but not on production with adapter static. |
@Rich-Harris Yes, I have pages with dynamic data but since I'm static rendering the whole site, that data would be loaded client-side. You might wonder why I'm not just using an SPA style fallback in that case. Because, I like to prerender the skeleton of each individual page, as much as can be rendered without having any data, to get those appearing instantly before any hydration happens. Better experience, less spinners. @dummdidumm Correct. It does seems like kind of an edge case I realize. At the moment I think my best workaround is to recursively rename |
@gbkwiatt @johnnysprinkles as an aside, it sounds like this will result in flashes of missing data as you navigate around the app — might be better to do the loading in How many proxy endpoints are we talking about? Would it make sense to implement them via |
I am afraid I can't use node on production environment and that's where the problem is. Not sure why it used to be possible and worked fine and now it's not. But that just means I will need some script to remove dynamic routes before using adapter static, but also keep node environment still running. It is a bit of edge case, but I am in a bit of an impass now. |
@Rich-Harris There's only one, so yeah, turns out I can make it a hook. See latest commit at https://github.com/johnnysprinkles/sveltekit_static_dynamic/commit/96852f58a344951b89c13eaf2cfa2b0d2c1ae72b I think we should leave this issue open though just because an endpoint leveraging the routing system would be nicer and more elegant. And yeah, for that aside, I can explore doing the loading in |
@Rich-Harris @gbkwiatt Think there is some confusion with how we are using We have normal page routes like We have many of these server routes like this, some which produce images, some produce json files. We obviously don't want these server routes to be directly prerendered themselves because that doesn't make sense. However, we require them to be present and running when the crawler is statically generating the site. So with the new changes to the routing system, how would we achieve what we were doing before? We've tried converting our old server routes to the new Your comment earlier suggested we need to use a different adapter instead of
|
Why not? It sounds like prerendering them is exactly what you want to do. |
but how do you prerender something like import { json } from '@sveltejs/kit';
export async function GET() {
return json({ message: 'OK' });
} If I mark this one as to prerender I get sounds like you have something in mind that we obviously missed |
I encountered this situation in a Discord question. There the problem was (and maybe for you, too) that the server endpoint never was called, so it didn't turn up in the list of prerendered things. This produces a dead lock because either there's an error about the page not being prerendered or an error about a dynamic route being present. To get out of it you either need to remove that server endpoint or use another adapter, because the whole point of adapter-static is that there's no server runtime, just some html/js/css files lying around on a static file server. |
Well it all makes sense, but in our case we need both at some point, have a static site and have a node site with dynamic routes. Why does it have to be like this ? Why it can't just omit those marked as prerender = false ? |
Because that's a much bigger footgun and source of confusion. It might seem silly to you, but people used to constantly ask why their
|
But Considering we could do this before and we've now lost functionality, and seemingly the only option to get it back is to either completely change the way we're hosting our site (not an option) or to rewrite the functionality of |
I'm thoroughly confused at this point. I have a site with completely static content (not a single |
I found out that for some reason even that I have +layout.js in a root with prerender true, I still have to mark some of the routes as prerender true with separated layout.js inside that route. Also it could have something to do with option in a config |
A minimum reproducible would be great |
https://github.com/jamesb93/static-site-repro This produces the error if you |
That's expected, by default nothing is prerendered, you need to opt in to that, and the error message even tells you how - by adding |
added +layout.js to jamesb93 repro and also a route |
From what I've noticed Not sure why is that, since I was under impression, if you add |
It's all there in the docs. |
I'm still baffled by the change, not in terms of design but what I need to do to make it work "as before". I don't use any fancy databases or anything with Svelte and basically use it like a static site generator. There isn't a single bit of dynamic content that can't be pre-rendered AFAIK. Can someone use my website as a learning lesson for me and other people on how to make it all work just fine with the static adapter? |
You commented already on this thread, and my response to that is the solution:
Did you try that yet? I also asked you some questions, so I'm asking them again:
I don't mean to come across rude, I'm just curious. |
That's fine. I understand you're trying to understand it from the user perspective. I did try your suggestion of adding a
For example, one of the routes that it whinges about is literally just this: <script>
import { goto } from '$app/navigation';
import { onMount } from 'svelte';
onMount(async () => [goto('https://www.github.com/jamesb93/ftis')]);
</script> and another... <a href='/patches/samplebrain_max.maxpat' download>samplebrain max experimentation</a> |
You are on a rather old version of
|
I just want to add, that after thinking all this through I do agree that adpater-static should just deal with renderable routes, and not to to prerender server routes. (on some cases it actually works if you mark server route for prerender). However it would be really good addition, if we could mark routes to be not picked up at all by adapter. Currently I have a script that copied only prerendable routes and build with adapter static with those routes. But it would be great if I could just mark route for not being picked up by build at all. Other than that I think it's all clear to me now. |
Ah. I forgot that I pinned the version of kit and so Thanks! |
* [fix] more info about prerendering errors Helps with #7183 and #7244 * Apply suggestions from code review * swap ternary around, remove dead code * small tweak * another minor tweak * drive-by-fix * tweak when prerender.entries suggestion appears * tweak * add strict option * Apply suggestions from code review Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Rich Harris <[email protected]>
As mentioned in the previous comment, the static parts of the site are written to As of #7264 there's a more comprehensive error message, and |
Just to follow up here, I'm using |
Also, another follow-up, I just switched to using Vite's built-in SSL capabilities with something like this in my vite.config.js
So no need for either a dev-only |
This sounds like something I need. I am using capacitorJS that bundles in a javascript "front-end" together with a webview in a native Android/iOS app. Thus, I only need the "frontend"-part of the build, so that I can embed that into the capacitorjs app on the phone. Then I need the "backend"-part to run on a server. Currently, I am using adapter-node to create the backend (and frontend) build that I run on the server. But if I then use adapter-static, it's not able to use things like FormActions. What is the correct way to solve this? Thus not serving the front-end from node, but rather separate the 2 to be hosted separately. If I do it the way you describe, how would I configure the base-url that the front-end part should use? Thanks! |
Describe the bug
One last issue on my big SvelteKit 350 to 551 upgrade... I'm using adapter-static to spit out some HTML files and serving those statically, some of those are even dynamic routes and that works fine with
export const prerender = true
.The issue I'm having though is, I have a backend proxy I only use in development mode. You can see it added to my repro case in this commit: https://github.com/johnnysprinkles/sveltekit_static_dynamic/commit/e91dbdf61d410d817988b06c890513c76bbd6376 In that example it returns a simple string, but in real life is make an HTTP fetch to my actual backend.
With that in place, "npm run build" ends up failing with this message:
Is there a way to make the "dynamic route" check logic ignore server endpoints?
Reproduction
The repro is in https://github.com/johnnysprinkles/sveltekit_static_dynamic
If you sync the latest version of that, you can "npm run dev" and everything works using the backend proxy. But "npm run build" fails. It seems like adapter static should just ignore any +server.js files.
Logs
No response
System Info
Severity
blocking an upgrade
Additional Information
No response
The text was updated successfully, but these errors were encountered: