Skip to content

fix(nextjs): preserve directive prologues in turbopack loaders#20103

Closed
igz0 wants to merge 1 commit intogetsentry:developfrom
igz0:fix/turbopack-multi-directives
Closed

fix(nextjs): preserve directive prologues in turbopack loaders#20103
igz0 wants to merge 1 commit intogetsentry:developfrom
igz0:fix/turbopack-multi-directives

Conversation

@igz0
Copy link
Copy Markdown

@igz0 igz0 commented Apr 4, 2026

Fixes #20101.

Summary

When _experimental.turbopackApplicationKey is enabled, the Next.js Turbopack loaders inject code for metadata/value propagation.

The previous implementation relied on a regex that only handled a single directive prologue entry. For modules that start with multiple directives, such as:

"use strict";
"use client";

the injected code could end up between the directives and break the "use client" classification.

This replaces the regex-based insertion point detection with a small linear scanner that:

  • skips leading whitespace and comments
  • walks consecutive directive prologue entries
  • returns the insertion point immediately after the last directive

Tests

  • added coverage for multiple directives
  • added coverage for comments between directives
  • added coverage for semicolon-free directives
  • added coverage for non-directive string literals that must not be skipped

Verification

Using the reproduction from #20101 with the patched @sentry/nextjs tarball:

  • npm run build completes successfully
  • /_not-found prerendering succeeds
  • the previous TypeError: (0, g.useEffect) is not a function no longer occurs

@sdk-maintainer-bot sdk-maintainer-bot bot added missing-maintainer-discussion Used for automated community contribution checks. violating-contribution-guidelines Used for automated community contribution checks. labels Apr 4, 2026
@sdk-maintainer-bot
Copy link
Copy Markdown

This PR has been automatically closed. The referenced issue does not show a discussion between you and a maintainer.

To avoid wasted effort on both sides, please discuss your proposed approach in the issue first and wait for a maintainer to respond before opening a PR.

Please review our contributing guidelines for more details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Deps

  • Bump lodash.template from 4.5.0 to 4.18.1 by dependabot in #20085
  • Bump @xmldom/xmldom from 0.8.3 to 0.8.12 by dependabot in #20066

Other

  • (core) Support embeddings in langchain by nicohrubec in #20017
  • (core, node) Portable Express integration by isaacs in #19928
  • (deno) Add denoRuntimeMetricsIntegration by chargome in #20023
  • (node, bun) Enforce minimum collection interval in runtime metrics integrations by chargome in #20068

Bug Fixes 🐛

  • (aws-serverless) Add timeout to _endSpan forceFlush to prevent Lambda hanging by logaretm in #20064
  • (cloudflare) Ensure every request instruments functions by JPeer264 in #20044
  • (gatsby) Fix errorHandler signature to match bundler-plugin-core API by JPeer264 in #20048
  • (nextjs) Preserve directive prologues in turbopack loaders by igz0 in #20103

Internal Changes 🔧

Core

  • Do not emit spans for chats.create in google-genai by nicohrubec in #19990
  • Unify .do* span ops to gen_ai.generate_content by nicohrubec in #20074
  • Simplify addResponseAttributes in openai integration by nicohrubec in #20013
  • Extract shared endStreamSpan for AI integrations by nicohrubec in #20021
  • Remove provider-specific AI span attributes in favor of gen_ai attributes in sentry conventions by nicohrubec in #20011

Deps

  • Bump mshick/add-pr-comment from dd126dd8c253650d181ad9538d8b4fa218fc31e8 to e7516d74559b5514092f5b096ed29a629a1237c6 by dependabot in #20078
  • Bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.24.1 to 2.25.2 by dependabot in #20081

Other

  • (node) Add node integration tests for Vercel ToolLoopAgent by nicohrubec in #20087
  • Update validate-pr workflow by stephanie-anderson in #20072
  • Remove unused tsconfig-template folder by mydea in #20067

🤖 This preview updates automatically when you update the PR.

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

Labels

missing-maintainer-discussion Used for automated community contribution checks. violating-contribution-guidelines Used for automated community contribution checks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_experimental.turbopackApplicationKey breaks React useEffect during SSR prerendering (Next.js 16 + Turbopack)

1 participant