Skip to content

fix: handle missing tables in generateStaticParams during build#63

Merged
axxs merged 1 commit into
mainfrom
fix/build-missing-tables
Mar 14, 2026
Merged

fix: handle missing tables in generateStaticParams during build#63
axxs merged 1 commit into
mainfrom
fix/build-missing-tables

Conversation

@axxs

@axxs axxs commented Mar 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • Wraps generateStaticParams in [slug]/page.tsx and news/[slug]/page.tsx with try/catch
  • Returns empty array when the pages/posts tables don't exist yet (e.g., first Docker build before Payload runs migrations)
  • dynamicParams = true ensures all pages still render on-demand at runtime

Fixes the build error: relation "pages" does not exist during next build.

Test plan

  • Docker build succeeds with empty/new database
  • Pages and posts still accessible at runtime after Payload creates tables

Wrap generateStaticParams queries in try/catch so the Next.js build
succeeds before Payload has created the pages/posts tables. Pages are
still served at runtime via dynamicParams = true.
@axxs axxs merged commit aaffee0 into main Mar 14, 2026
@axxs axxs deleted the fix/build-missing-tables branch March 14, 2026 10:24
@claude

claude Bot commented Mar 14, 2026

Copy link
Copy Markdown

Code Review -- PR #63: fix: handle missing tables in generateStaticParams during build. Overall: The fix is minimal and targeted, and dynamicParams=true was already in place so the runtime fallback path is solid. Main concern: The empty catch block silences every error, not just the missing-table case. Network failures, misconfigured Payload, or query bugs would all silently return [] making them impossible to debug. Suggested fix: check err.message for the Postgres 42P01 signature ('does not exist') and re-throw anything else -- suppress only the known migration-time error. Also note per CLAUDE.md that console.log() is forbidden in production, so use a proper logger. Secondary notes: (1) Code duplication across both page files is acceptable per CLAUDE.md guidance against premature abstractions. (2) dynamicParams=true was already correct. (3) Test coverage: a unit test mocking payload.find to throw would give regression coverage. Summary: The fix solves the immediate build problem. The one actionable suggestion is narrowing the catch so unexpected errors are not silently swallowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant