Skip to content

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

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

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

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@github-actions github-actions Bot added the stale label Sep 7, 2026

Copy link
Copy Markdown
Author

Still actively interested in getting this fix reviewed. The PR is ready from my side; the current Actions runs are showing action_required, so I’m leaving it as draft until the required checks can run successfully.

@github-actions github-actions Bot removed the stale label Sep 8, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@github-actions github-actions Bot added the stale label Sep 15, 2026

Copy link
Copy Markdown
Author

Still active. The PR remains draft because the current Actions runs are still action_required; there are no unresolved review threads at the moment.

@github-actions github-actions Bot removed the stale label Sep 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@github-actions github-actions Bot added the stale label Sep 23, 2026
@dustinbyrne

Copy link
Copy Markdown
Contributor

hey @kkumarsatish567-dot, thanks for the pull request! sorry for the delayed response here, we typically don't look into pull requests until they're marked ready for review.

i've run CI for your branch. just a heads up - this will also require a changeset and your commits to be signed in order for us to approve and merge. please take a look at CONTRIBUTING.md for more information.

@github-actions github-actions Bot removed the stale label Sep 29, 2026
@dustinbyrne

Copy link
Copy Markdown
Contributor

thanks again for working on this! i'd missed that we'd already resolved #4667 through a CLI fix in PostHog/posthog#91427, adopted in #4737 and released in @posthog/nextjs-config@1.11.0.

the CLI now uploads the same source pairs it injected, so we no longer need to snapshot file paths in the next.js integration. i'll close this as superseded, but feel free to re-open unless i've missed something!

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)

2 participants