lazarv / react-server

The easiest way to build React apps with server-side rendering
https://react-server.dev
MIT License
122 stars 6 forks source link

static generation / TypeError: configRoot.export is not iterable #81

Open aheissenberger opened 1 day ago

aheissenberger commented 1 day ago

Describe the bug

I run react-server build and expect static output for all pages with an xxx.static.ts file:

about/page.tsx
about/page.static.ts
product/[id].tsx
product/[id].static.ts

react-server.config.json

{
    "root": "src/pages",
    "public": "src/public"
}

1) Error: TypeError: configRoot.export is not iterable @lazarv/react-server/lib/build/static.mjs:110:28

I think : [...configRoot.export, ...paths]; should be changed to : [...(configRoot?.export??[]), ...paths];

2) Dynamic static routes product/[id].static.ts

I first tried based on your documentation with this: export default [{ id: 1 }, { id: 2 }, { id: 3 }]; which broke here static.mjs:129 as there was no path property and replace did not check if the property path exists.

What worked was this: export default [{ path: "/product/1" }, { path: "/product/2" }, { path: "/product/3" }];

react-server/0.0.0-experimental-3955213-20241116-c7cdeda5 building static for production
.react-server/dist/product/2/index.html       4.94 kB │ gzip:  1.51 kB │ brotli:  1.23 kB
.react-server/dist/product/1/index.html       4.95 kB │ gzip:   1.5 kB │ brotli:  1.22 kB
.react-server/dist/product/3/index.html       4.93 kB │ gzip:   1.5 kB │ brotli:  1.22 kB
.react-server/dist/product/1/x-component.rsc  1.89 kB │ gzip:    737 B │ brotli:    621 B
.react-server/dist/product/2/x-component.rsc  1.89 kB │ gzip:    742 B │ brotli:    629 B
.react-server/dist/product/3/x-component.rsc  1.88 kB │ gzip:    733 B │ brotli:    624 B

3) Page without props about/page.static.ts

content: export default true;

No static page is created - see output building static for production section 2) I got a static page, if added the path /about to react-server.config.json

{
    "root": "src/pages",
    "public": "src/public",
    "export": [{"path":"/about"}]
}

Reproduction

https://github.com/aheissenberger/bug-rs-static-reder-demo

Steps to reproduce

pnpm build

System Info

System:
    OS: macOS 15.1.1
    CPU: (12) arm64 Apple M4 Pro
    Memory: 10.08 GB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.3.0 - /opt/homebrew/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.9.0 - /opt/homebrew/bin/npm
    pnpm: 9.14.4 - /opt/homebrew/bin/pnpm
    bun: 1.1.38 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 131.0.6778.108
    Safari: 18.1.1
    Safari Technology Preview: 18.2
  npmPackages:
    @lazarv/react-server: 0.0.0-experimental-3955213-20241116-c7cdeda5 => 0.0.0-experimental-3955213-20241116-c7cdeda5

Used Package Manager

pnpm

Logs

No response

Validations

lazarv commented 15 hours ago

Hi! Thanks for the detailed report! Static route parameter definitions should now work with the latest version as described in the documentation, so please upgrade.

The previous version only supported the path object format ({ path }) which was described in the docs at https://react-server.dev/router/static#override-static-paths. With this change, the file-system based router is trying to apply route parameters defined in the static file to the route path with a fallback to the original path object format.

aheissenberger commented 15 hours ago

This works: export default [{ id: 1 }, { id: 2 }, { id: 3 }];

but this still throws an error (with and without async):

import { products } from '../../data/products'
export default  () => products.map(p => ({ id: p.id}))
react-server/0.0.0-experimental-61cbefd-20241204-b7fff15a building static for production
Error: path property is not defined for 4 paths
    at file:/shop/node_modules/.pnpm/@lazarv+react-server@0.0.0-experimental-61cbefd-20241204-b7fff15a_@types+node@22.10.1_rollup@_4vfvp67tg5juqdb6xcq6lyosle/node_modules/@lazarv/react-server/lib/build/static.mjs:113:15
    at async file:/shop/node_modules/.pnpm/@lazarv+react-server@0.0.0-experimental-61cbefd-20241204-b7fff15a_@types+node@22.10.1_rollup@_4vfvp67tg5juqdb6xcq6lyosle/node_modules/@lazarv/react-server/server/runtime.mjs:29:9