router icon indicating copy to clipboard operation
router copied to clipboard

Unable to resolve static server function json (main/devinxi)

Open danecando opened this issue 7 months ago • 5 comments

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

  1. pnpm i
  2. pnpm build
  3. pnpm start
  4. 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

Image

Platform

  • OS: MacOS
  • Browser: Chrome
  • Version: 136

Additional context

No response

danecando avatar May 18 '25 15:05 danecando

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 alpha tag.
  • 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.

SeanCassiere avatar May 27 '25 08:05 SeanCassiere

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 devinxi concept.

airtonix avatar May 30 '25 21:05 airtonix

@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:

This should be an equivalent - https://github.com/TanStack/router/blob/alpha/docs/start/framework/react/build-from-scratch.md

SeanCassiere avatar May 31 '25 04:05 SeanCassiere

@SeanCassiere will do in the next couple of days.

airtonix avatar May 31 '25 06:05 airtonix

@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.

danecando avatar Jun 12 '25 22:06 danecando

+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.

alekhinen avatar Jul 19 '25 19:07 alekhinen

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.

schiller-manuel avatar Sep 28 '25 22:09 schiller-manuel