Using URL search params with prerendered route
Here's a personal project that uses a static createServerFn for data with route prerendering. The itemHeight search state controls the adjustable height of each gradient list item. As result of the prerendering, the default itemHeight is always rendered on initial page load breaking the adjustable height feature.
Id be fine just using SSR here, but when prerendering is disabled I get build errors - I assume because of the static createServerFn expects prerendering to be on. Using a regular createServerFn solves my problem, but then the returned data isn't bundled at build time as static json.
Is it possible to use url search state with prerendering/static createServerfn? Perhaps with something similar to how theming is done discussed in this thread using the ScriptOnce component?
Grabient | CSS Gradient Generator & Palette Finder
Use Grabient, a cosine gradient generator, to create custom CSS gradients and discover inspiring color palettes. Perfect for designers and developers.
17 Replies
generous-apricot•6mo ago
can you share some code?
what does "when it's disabled" mean here? which build errors?
what is breaking?
stormy-goldOP•6mo ago
sorry i should have proof read this a bit more
i meant when prerendering is disabled i get build errors
i assumed that was because the static createServerFn expects prerendering to be on? Could be entirely wrong there
i can just make the repo public. one sec
stormy-goldOP•6mo ago
GitHub
GitHub - johnkorzhuk/grabient22
Contribute to johnkorzhuk/grabient22 development by creating an account on GitHub.
generous-apricot•6mo ago
where are the search params used?
stormy-goldOP•6mo ago
index route
pretty much everything is in the index route rn
generous-apricot•6mo ago
but that server function does not use those search params? https://github.com/johnkorzhuk/grabient22/blob/main/src/lib/fetchCollections.ts
GitHub
grabient22/src/lib/fetchCollections.ts at main · johnkorzhuk/grabi...
Contribute to johnkorzhuk/grabient22 development by creating an account on GitHub.
stormy-goldOP•6mo ago
the server function is just used to fetch data
unrelated to the search params. sorry for the confusion
generous-apricot•6mo ago
so which build errors do you get when prerendering is disabled?
stormy-goldOP•6mo ago
im just using the url for state instead of cookies
its not a build error. its a server runtime error actually
stormy-goldOP•6mo ago
Grabient | CSS Gradient Generator & Palette Finder
Use Grabient, a cosine gradient generator, to create custom CSS gradients and discover inspiring color palettes. Perfect for designers and developers.
stormy-goldOP•6mo ago
im not too familiar with netlify. vercel would have logs to look at
the error build is from the commit "fuego"
the only relevant change in that commit was in the app.config.ts where i commented out the prerendering
stormy-goldOP•6mo ago
everything was deployed on that commit fine. Definately not a build time error, my mistake

generous-apricot•6mo ago
i see
looks like the static server functions tries to write the not yet cached value to disk and that fails
so how would you expect that cached value to be actually... cached?
stormy-goldOP•6mo ago
so im trying to do something with a static server function that just isnt going to work?
generous-apricot•6mo ago
at least not in the default impl that tries to write a file to disk
in your runtime env on netlify thats not going to work
at least not in that directory
stormy-goldOP•6mo ago
Hopefully to clear things up: The search params dont effect anything with the build or the server function. Search params are used for the ui much like how you would use cookies for ui state in an SSR website. Because the route is prerendered, on initial load the ui shows the prerendered (default search params state) even when the url has a different itemHeight set.
I mentioned how the project is built because when I opt out of prerendering and switch to a regular createServerFn everything works. But then I dont get the benefits of the data being treated like a static asset (caching, database being hit once a day/per build vs on every request)
generous-apricot•6mo ago
ah
is there an actual writable directory at runtime?