Static Prerendering in 1.121
Which project does this relate to?
Start
Describe the bug
Is Static Prerendering gone with version 1.121 ? I carefully updated my app, and even started a new one from scratch to try out.
My config is:
export default defineConfig({
server: {
port: 3000,
preset: 'static',
prerender: {
routes: ['/'],
crawlLinks: true
}
},
...
It seems that preset 'static' does nothing, there is no html in .output/public. And I have index.mjs in .output/server as if I was building for ssr, or with node-server preset or something.
I need to deploy to aws/amplify and since it is not (yet?) supported in ssr, I need this static pre-rendering..
Your Example Website or App
Steps to Reproduce the Bug or Issue
Expected behavior
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome, Safari, Firefox
- Version: 1.121
Additional context
No response
It looks as though the TanStack Start plugin now forwards the value from target, cf. https://github.com/TanStack/router/blob/4014a00454ebd794bdcdfc25e74f42fe2f952d19/packages/start-plugin-core/src/schema.ts#L88
So your config should look something like... (untested):
export default defineConfig({
server: {
port: 3000,
},
plugins: [
tanstackStart({
target: 'static',
prerender: {
// ...
},
}),
],
// ...
});
@julen Thanks for the link. It helped me understand how to make ssr work on amplify with nitro preset aws_amplify. But prerender is still not working, no matter what I try.
export default defineConfig({
server: {
port: 3000
},
plugins: [
tsConfigPaths({
projects: ['./tsconfig.json']
}),
tanstackStart({
target: 'aws_amplify',
prerender: {
enabled: true // ???
}
}),
In router/packages/start-plugin-core/src/schema.ts#L125 , I see this, but I don't know if its is the right object to configure, and how:
prerender: z
.object({
enabled: z.boolean().optional(),
concurrency: z.number().optional(),
filter: z.function().args(pageSchema).returns(z.any()).optional(),
failOnError: z.boolean().optional(),
})
.and(pagePrerenderOptionsSchema.optional())
.optional(),
I came to the same issue:
My previous configuration looked something like:
server: {
preset: "vercel",
hooks: {
"prerender:routes": async (routes) => {
const baseRoutes = [
"/",
"/blog",
"/services",
"/pricing",
"/contact",
];
baseRoutes.forEach((route) => {
routes.add(route);
});
const posts = await listBlogPostsRoutes();
posts.forEach((post) => {
routes.add(post);
});
},
},
prerender: {
concurrency: 50,
routes: [],
crawlLinks: false,
},
},
I cannot find how I can setup the hooks part with the updated version. Anyone knows how ?
they considerably re-worked the whole setup: vite plugin instead of vinxi, app.config.ts is totally gone.. but rolled it out just as usual 1.x update, with docs not updated either.. no good 🤦♂️
Just stay on 1.200.11 until dust settle down
I'm not sure if this is what you're looking for, but there is a prerender setting under spa mode:
https://tanstack.com/start/latest/docs/framework/react/spa-mode#prerendering-options
In my case, enabling this allowed me to deploy in the same way as with the vinxi version.
1c1,2
< import { defineConfig } from "@tanstack/solid-start/config";
---
> import { tanstackStart } from "@tanstack/solid-start/plugin/vite";
> import { defineConfig } from "vite";
5,14c6,18
< vite: {
< plugins: [
< tsConfigPaths(),
< ],
< },
< server: {
< prerender: {
< routes: ["some-paths"],
< },
< },
---
> plugins: [
> tsConfigPaths(),
> tanstackStart({
> spa: {
> enabled: true,
> prerender: {
> enabled: true,
> crawlLinks: true,
> },
> },
> target: "cloudflare-pages-static",
> }),
> ],
Update: The above config stopped working with v1.125.6 (or an older version?) in my environment...
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
import { defineConfig, PluginOption } from 'vite';
import tsConfigPaths from 'vite-tsconfig-paths';
export default defineConfig({
server: {
port: 3000,
},
plugins: [
tsConfigPaths({
projects: ['./tsconfig.json'],
}),
tanstackStart({
target: 'static',
pages: [
{
path: '/',
prerender: {
crawlLinks: true,
enabled: true,
},
},
],
}),
],
});
It's my config,may be helpful.
import { tanstackStart } from '@tanstack/react-start/plugin/vite'; import { defineConfig, PluginOption } from 'vite'; import tsConfigPaths from 'vite-tsconfig-paths'; export default defineConfig({ server: { port: 3000, }, plugins: [ tsConfigPaths({ projects: ['./tsconfig.json'], }), tanstackStart({ target: 'static', pages: [ { path: '/', prerender: { crawlLinks: true, enabled: true, }, }, ], }), ], });It's my config,may be helpful.
Damn i messed so much around.