T
TanStack6mo ago
stormy-gold

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
generous-apricot6mo ago
can you share some code? what does "when it's disabled" mean here? which build errors? what is breaking?
stormy-gold
stormy-goldOP6mo 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-gold
stormy-goldOP6mo ago
GitHub
GitHub - johnkorzhuk/grabient22
Contribute to johnkorzhuk/grabient22 development by creating an account on GitHub.
generous-apricot
generous-apricot6mo ago
where are the search params used?
stormy-gold
stormy-goldOP6mo ago
index route pretty much everything is in the index route rn
generous-apricot
generous-apricot6mo 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-gold
stormy-goldOP6mo ago
the server function is just used to fetch data unrelated to the search params. sorry for the confusion
generous-apricot
generous-apricot6mo ago
so which build errors do you get when prerendering is disabled?
stormy-gold
stormy-goldOP6mo ago
im just using the url for state instead of cookies its not a build error. its a server runtime error actually
stormy-gold
stormy-goldOP6mo 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-gold
stormy-goldOP6mo 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-gold
stormy-goldOP6mo ago
everything was deployed on that commit fine. Definately not a build time error, my mistake
No description
generous-apricot
generous-apricot6mo ago
i see
DefaultCatchBoundary Error: Error: ENOENT: no such file or directory, mkdir '/opt/build'
DefaultCatchBoundary Error: Error: ENOENT: no such file or directory, mkdir '/opt/build'
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-gold
stormy-goldOP6mo ago
so im trying to do something with a static server function that just isnt going to work?
generous-apricot
generous-apricot6mo 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-gold
stormy-goldOP6mo 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
generous-apricot6mo ago
ah is there an actual writable directory at runtime?

Did you find this page helpful?