-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
feat: static build caching for server functions #2926
base: main
Are you sure you want to change the base?
Conversation
ec52d17
to
3e6498e
Compare
☁️ Nx Cloud ReportWe didn't find any information for the current pull request with the commit b1fd9ef. Check the Nx Cloud Source Control Integration documentation for more information. Alternatively, you can contact us at [email protected]. Sent with 💌 from NxCloud. |
@@ -18,6 +18,7 @@ import { config } from 'vinxi/plugins/config' | |||
import { serverFunctions } from '@vinxi/server-functions/plugin' | |||
// @ts-expect-error | |||
import { serverTransform } from '@vinxi/server-functions/server' | |||
import { createNitro } from 'nitropack' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the package.json
we should move this from devDependencies
to dependencies
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should
@@ -0,0 +1,31 @@ | |||
{ | |||
"name": "tanstack-start-example-basic-static", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping this here as a reminder that we should duplicate this example into the e2e/start
directory and run the end-to-end test on the built output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
}) | ||
} | ||
|
||
function getStaticCacheUrl(options: MiddlewareCtx, hash: string) { | ||
return `/__tsr/staticServerFnCache/${options.filename}__${options.functionId}__${hash}.json` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The base needs to be customizable since we've had people host their app on a subpath. It'd just be a matter of injecting the values from start's config as env vars like done for getBaseUrl impl for server-fns.
❌ Deploy Preview for start-basic-static failed. Why did it fail? →
|
…uter into feat-static-serverFn
This adds a new concept of "server function type". By default, all server functions are dynamic, meaning they will reach out to the server to execute. This addition brings a new type of
static
, which can be configured in a few places:As the default
As an dynamic function of the data/context
At the call site of the serverFn
It falls into this order with the rest of the builder API:
How it works
type
is sent to the server with the requestCustomizing the
serverFnStaticCache
You can create and set your own
serverFnStaticCache
by using thecreateServerFnStaticCache
andsetServerFnStaticCache
functions.Imagine we might want to cache the output of the server function to giant massive JSON file (don't do this). We could do something like this:
Imagine the other places you could technically create this cache:
More cool things
error
key