Skip to content

fix(next-plugin): reserve shared class slots before next dev extracts - #939

Merged
owjs3901 merged 2 commits into
mainfrom
fix/next-shared-slots
Nov 17, 2026
Merged

owjs3901 merged 2 commits into
mainfrom
fix/next-shared-slots

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes audit item NXT-01 (P1, NONDET). On main, file numbers are already seeded in path order (seedFileNumbers), but a class slot shared by several files still gets the next free slot of the file that extracted that class first. next dev skips the sorted production prewarm and the coordinator extracts in the order Turbopack requests arrive, so class names could differ on every start, even for the same project.

  • In next dev (Turbopack), shared slots are reserved in path order with createSharedSlotReservation(wasm).reserve(...) before the coordinator starts. This is the same engine API the webpack / Rsbuild / Vite plugins already use.
    • Scan targets: src, app, pages, and include packages (the same roots as the file number seed)
    • filename is a POSIX path relative to the same cwd as the coordinator, cssDir uses the same ./<relative> form as the coordinator, and importMainCssInCode=false, importMainCssInCss=true match the coordinator's extraction options.
  • One-shot builds (next build) still extract in path order via the prewarm, so no reservation is added there (to avoid one more extraction pass).
  • If the reservation fails, like the file number seed, it falls back best-effort to arrival order.
  • Removed the "existing shared slots remain arrival-ordered" part of the atomHoist warning text, which is no longer true.

Overlap with other PRs

Test plan

  • bun test --coverage src/__tests__/plugin.test.ts: plugin.ts 100% lines / functions
    • No reservation in production
    • In development, reserves with wasm, and roots / include / package / toId / cssDir / CSS options match the coordinator
    • Setup doesn't fail even if the reservation throws
  • bunx tsc --noEmit -p packages/next-plugin
  • bunx prettier --single-quote --no-semi --check (changed files)
  • Locally, 3 tests in plugin.test.ts (native engine / seedFileMap) fail the same way on main too, because of stale WASM / native builds.

요약

감사 항목 NXT-01 (P1, NONDET) 수정입니다. main에서 파일 번호는 이미 경로 순서로 seed되지만 (seedFileNumbers), 여러 파일이 공유하는 class slot은 여전히 그 클래스를 먼저 추출한 파일의 다음 빈 slot을 받습니다. next dev는 정렬된 프로덕션 prewarm을 건너뛰고 코디네이터가 Turbopack 요청 도착 순서대로 추출하므로, 같은 프로젝트라도 시작할 때마다 클래스 이름이 달라질 수 있었습니다.

  • next dev (Turbopack)에서 코디네이터를 시작하기 전에 createSharedSlotReservation(wasm).reserve(...)로 공유 slot을 경로 순서대로 미리 예약합니다. webpack / Rsbuild / Vite 플러그인이 이미 쓰는 것과 같은 엔진 API입니다.
    • 스캔 대상: src, app, pages와 include 패키지 (파일 번호 seed와 같은 루트)
    • filename은 코디네이터와 같은 cwd 기준 POSIX 경로, cssDir도 코디네이터와 같은 ./<relative> 형식이고, importMainCssInCode=false, importMainCssInCss=true로 코디네이터 추출 옵션과 일치시켰습니다.
  • 단발 빌드(next build)는 기존처럼 prewarm이 경로 순서로 추출하므로 예약을 추가하지 않았습니다 (추출이 한 번 더 늘어나는 것을 피하기 위해).
  • 예약이 실패하면 파일 번호 seed와 마찬가지로 best-effort로 도착 순서에 맡깁니다.
  • atomHoist 경고 문구에서 더 이상 사실이 아닌 "existing shared slots remain arrival-ordered" 부분을 지웠습니다.

다른 PR과의 겹침

테스트 계획

  • bun test --coverage src/__tests__/plugin.test.ts: plugin.ts 100% lines / functions
    • production에서는 예약하지 않음
    • development에서는 wasm으로 예약하고, roots / include / package / toId / cssDir / CSS 옵션이 코디네이터와 일치
    • 예약이 throw해도 setup이 실패하지 않음
  • bunx tsc --noEmit -p packages/next-plugin
  • bunx prettier --single-quote --no-semi --check (변경 파일)
  • 로컬에서 plugin.test.ts의 3개 테스트(native 엔진 / seedFileMap)는 오래된 WASM / native 빌드 때문에 main에서도 동일하게 실패합니다.

Refs #694

🤖 Generated with Claude Code

File numbers are seeded in path order, but a class that several files
share still took the next free slot of whichever file Turbopack
extracted first. next dev skips the sorted production prewarm and the
coordinator extracts in request order, so the same project could get
different class names on each start.

Under next dev the Turbopack setup now reserves every shared slot with
createSharedSlotReservation before the coordinator starts, scanning
src, app and pages plus included packages with the coordinator's own
filenames and CSS directories, as the webpack, Rsbuild and Vite
plugins already do. One-shot builds keep relying on the prewarm, which
extracts in path order. A failing reservation falls back to arrival
order like the file-number seed.

Refs #694

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
packages/next-plugin/src/plugin.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Keep #918's setupWarning/restoreSessionState next to reserveSharedSlots, and
warn through setupWarning when the reservation fails, like the other setup
fallbacks. #944 dropped the withTailwindCss import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owjs3901
owjs3901 merged commit 683f375 into main Nov 17, 2026
27 checks passed
@owjs3901
owjs3901 deleted the fix/next-shared-slots branch November 17, 2026 07:31
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Resolve the conflict with #938 in packages/next-plugin/src/coordinator.ts.
#938 adds no new module state: its error-returning waitForBase and
waitForBucket, missingFiles and incompleteCssError now read the app's own
CoordinatorState, so one app's extractions never complete another app's
CSS. A test covers two apps expecting the same base files. #939's
shared-slot reservation runs on the app's own engine session; its test
now expects that session instead of the shared engine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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