Skip to content

fix(nextjs-config): snapshot sourcemap inputs for Turbopack - #4691

Draft
kkumarsatish567-dot wants to merge 2 commits into
PostHog:mainfrom
kkumarsatish567-dot:fix/nextjs-turbopack-sourcemap-race
Draft

fix(nextjs-config): snapshot sourcemap inputs for Turbopack#4691
kkumarsatish567-dot wants to merge 2 commits into
PostHog:mainfrom
kkumarsatish567-dot:fix/nextjs-turbopack-sourcemap-race

Conversation

@kkumarsatish567-dot

Copy link
Copy Markdown

Problem

Fixes #4667.

Next.js 16.3+ can continue flushing Turbopack's filesystem cache after runAfterProductionCompile starts. @posthog/nextjs-config currently passes the entire .next directory to posthog-cli sourcemap process, so the CLI can observe one set of chunks during injection and a larger set during upload. Chunks created between those scans have no injected chunk ID and can fail the production build with Chunk ID not found.

Changes

  • Snapshot the JavaScript files under the compilation output before invoking the PostHog CLI.
  • Pass that explicit file list over the CLI's existing stdin mode so injection and upload operate on the same set of chunks.
  • Ignore files that materialize after the snapshot for that run instead of letting them invalidate the already-started sourcemap transaction.
  • Add regression coverage for a file appearing while CLI processing is in progress, plus .js/.mjs/.cjs, empty-output, and missing-output cases.

This avoids timing sleeps/retries and keeps the fix local to the integration lifecycle race.

Testing

CI requested via this draft PR. The focused unit tests are in packages/nextjs-config/src/utils.spec.ts.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

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.

nextjs-config: sourcemap CLI races Turbopack filesystem cache in Next.js 16.3+ (Chunk ID not found)

1 participant