Unable to resolve static server function json (main/devinxi)
Which project does this relate to?
Start v1.121.4
Describe the bug
The application is unable to resolve the json file from a static server function at runtime.
I've reproduced the issue in start basic with a simple helloWorld static server function in the index route. After building and starting the application, a request to fetch the json file returns a 404.
The file exists in the build output at .output/public/__tsr/staticServerFnCache/*.json
Request URL
http://localhost:3000/__tsr/staticServerFnCache/cca98d135af30bb22ec3cb564f025daeedd83e22.json
Request Method
GET
Status Code
404 Not Found
Your Example Website or App
https://github.com/danecando/start-basic
Steps to Reproduce the Bug or Issue
-
pnpm i -
pnpm build -
pnpm start - Open the app, change the page, navigate back to the index page
Expected behavior
Can use a static server function like a regular server function to load data in a TS Start application
Screenshots or Videos
Platform
- OS: MacOS
- Browser: Chrome
- Version: 136
Additional context
No response
Looking at your example, there are two things to note.
- You need to update the packages to the newest release. This release had some fixes to the public assets. You can upgrade by simply using the
alphatag. - It looks like you don't have prerendering enabled. Without it, at build time the pages cannot be crawled so that the static json files can be created.
Seems like this would be helped with a little bit more knowledge transfer (avoiding interim churn escalations)
@SeanCassiere Are able to update https://github.com/TanStack/router/discussions/2863#discussioncomment-13104960 with the missing bits (there's a few TODO there)
- https://tanstack.com/start/latest/docs/framework/react/build-from-scratch is not applicable anymore for the upcoming
devinxiconcept.
@SeanCassiere Are able to update #2863 (comment) with the missing bits (there's a few TODO there)
I don't have all the options at the moment. If join our Discord, we can help you migrate your specific customized config.
Edit:
- tanstack.com/start/latest/docs/framework/react/build-from-scratch is not applicable anymore for the upcoming devinxi concept.
This should be an equivalent - https://github.com/TanStack/router/blob/alpha/docs/start/framework/react/build-from-scratch.md
@SeanCassiere will do in the next couple of days.
@SeanCassiere I updated the reproduction with a simple helloWorld static server function in the index route of the start-basic example from the latest release. Updating the description the to include the start version.
Edit: I missed the part about pre-rendering. I would leave the issue standing if that is the case though. I believe this should work out of the box either way especially if it's documented as a standalone feature.
+1 to @danecando's suggestion about having this work out of the box. There are use cases where having access to type: 'static' server functions in an SSR app would be very ergonomic. For example, I'd like my SSR app to have a static server function that returns build metadata (commit sha, build number, etc) which my client-side code can query for.
static server functions have been moved to a middleware https://tanstack.com/start/latest/docs/framework/react/static-server-functions it however still relies on prerendering which won't change anytime soon.