router icon indicating copy to clipboard operation
router copied to clipboard

Static Prerendering in 1.121

Open arnriu opened this issue 7 months ago • 5 comments

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

arnriu avatar Jun 10 '25 22:06 arnriu

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 avatar Jun 11 '25 09:06 julen

@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(),

arnriu avatar Jun 11 '25 13:06 arnriu

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 ?

abaudhuin avatar Jun 11 '25 14:06 abaudhuin

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

dannylin108 avatar Jun 12 '25 01:06 dannylin108

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

wancup avatar Jun 16 '25 14:06 wancup

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.

SexySix avatar Jul 02 '25 15:07 SexySix

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.

Fewknowme avatar Aug 15 '25 14:08 Fewknowme