Skip to content

fix(next-plugin): reload the Turbopack theme when devup.json changes - #944

Merged
owjs3901 merged 2 commits into
mainfrom
fix/next-theme-reload
Nov 17, 2026
Merged

owjs3901 merged 2 commits into
mainfrom
fix/next-theme-reload

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes audit item NXT-11 (P2, WRONG). On Turbopack, the theme was registered only once, while next.config was evaluated. Next does not re-read next.config when devup.json changes. Also, in coordinator mode the source loader and CSS loader did not depend on the theme file, only on the port file. So editing the theme during next dev was reflected neither in the extracted classes (typography / length / shadow tokens) nor in the sheet's theme variables, and the dev server had to be restarted.

  • Setup collects every file the theme was read from: devup.json, the configs it extends (inputs of loadDevupConfigSync), and the project's Tailwind CSS files (findTailwindCss().files).
  • themeFiles is passed in both loaders' options and, in coordinator mode, added with this.addDependency. When one of these files changes, Turbopack re-runs those loaders.
  • In next dev, theme: { files, reload } is passed to the coordinator. Right before /css and /extract, the coordinator compares the files' mtime / size, and if they changed it re-registers the theme and rewrites theme.d.ts. reload returns the new file list, so newly added extends are included in later change detection too.
  • If loading the theme fails, that request fails with that error, and the stamp is not updated, so the next request retries.
  • Theme registration was wrapped in a helper (registerProjectTheme) that calls findTailwindCss only once, producing the same result as the existing withTailwindCss.
  • Limitations: DEVUP_UI_DEFAULT_THEME (config.env) is set only at setup, so changing the default theme name still needs a restart. Also, the loader dependency list is as of setup time, so editing only an extends file added later does not re-run the loaders (editing devup.json does).

Overlap with other PRs

Test plan

  • bun test --coverage (plugin, coordinator, loader, css-loader): plugin.ts, coordinator.ts, loader.ts, css-loader.ts at 100% lines / functions
    • Coordinator: no reload before a file changes, exactly one reload when devup.json is edited, reload on /extract when a previously missing extends file appears
    • Coordinator: on reload failure, /css returns 500 + message (Error / non-Error), /extract returns a 500 JSON error, and the next request retries
    • loader / CSS loader: add themeFiles as dependencies in coordinator mode
    • plugin: theme.reload in the dev coordinator options re-registers the theme and returns the file list; the Tailwind CSS theme and its files are included in themeFiles
  • 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-11 (P2, WRONG) 수정입니다. Turbopack에서는 theme을 next.config 평가 중 한 번만 등록했습니다. Next는 devup.json이 바뀌어도 next.config를 다시 읽지 않습니다. 또 코디네이터 모드의 source loader와 CSS loader는 port 파일 외에는 theme 파일에 의존하지 않았습니다. 그래서 next dev 중 theme을 고쳐도 추출된 클래스(typography / length / shadow 토큰)와 시트의 theme 변수 어느 쪽에도 반영되지 않았고, dev 서버를 재시작해야 했습니다.

  • setup이 theme을 읽은 모든 파일을 모읍니다: devup.json, 그것이 extends하는 config들 (loadDevupConfigSync의 inputs), 프로젝트 Tailwind CSS 파일들 (findTailwindCss().files).
  • 두 loader 옵션에 themeFiles를 넘기고, 코디네이터 모드에서 this.addDependency로 추가합니다. 이 파일 중 하나가 바뀌면 Turbopack이 해당 loader들을 다시 실행합니다.
  • next dev에서는 코디네이터에 theme: { files, reload }를 넘깁니다. 코디네이터는 /css와 /extract 직전에 파일들의 mtime / size를 비교하고, 바뀌었으면 theme을 다시 등록하고 theme.d.ts를 다시 씁니다. reload는 새 파일 목록을 돌려주므로 새로 추가된 extends도 이후 변경 감지에 포함됩니다.
  • theme 로드가 실패하면 해당 요청이 그 에러로 실패하고, stamp를 갱신하지 않으므로 다음 요청에서 다시 시도합니다.
  • theme 등록은 기존 withTailwindCss와 같은 결과를 내도록 findTailwindCss를 한 번만 호출하는 helper(registerProjectTheme)로 묶었습니다.
  • 한계: DEVUP_UI_DEFAULT_THEME(config.env)는 setup에서만 정해지므로 기본 theme 이름 변경은 여전히 재시작이 필요합니다. 또 loader 의존성 목록은 setup 시점 기준이라, 나중에 추가된 extends 파일 편집만으로는 loader가 재실행되지 않습니다 (devup.json 편집은 재실행됨).

다른 PR과의 겹침

테스트 계획

  • bun test --coverage (plugin, coordinator, loader, css-loader): plugin.ts, coordinator.ts, loader.ts, css-loader.ts 100% lines / functions
    • 코디네이터: 파일 변경 전에는 reload하지 않음, devup.json 수정 시 한 번만 reload, 없던 extends 파일이 생기면 /extract에서 reload
    • 코디네이터: reload 실패 시 /css는 500 + 메시지 (Error / non-Error), /extract는 500 JSON 에러, 다음 요청에서 재시도
    • loader / CSS loader: 코디네이터 모드에서 themeFiles를 dependency로 추가
    • plugin: dev 코디네이터 옵션의 theme.reload가 theme을 다시 등록하고 파일 목록을 반환, Tailwind CSS theme과 그 파일들이 themeFiles에 포함
  • bunx tsc --noEmit -p packages/next-plugin
  • bunx prettier --single-quote --no-semi --check (변경 파일)
  • 로컬에서 plugin.test.ts의 3개 테스트(native 엔진 / seedFileMap)는 오래된 WASM / native 빌드 때문에 main에서도 동일하게 실패합니다.

Refs #686

🤖 Generated with Claude Code

Under Turbopack the theme was registered once, while next.config was
evaluated. Next does not reload next.config for devup.json, and in
coordinator mode neither loader depended on the theme files, so an
edited theme reached neither the extracted classes nor the sheet's
variables until the dev server restarted.

Setup now collects every file the theme is read from: devup.json, the
configs it extends and the project's Tailwind CSS. Both loaders add
them as dependencies in coordinator mode, so Turbopack re-runs them
when one changes. Under next dev the coordinator gets the same list and
a reload callback: before each /css and /extract it compares the files'
mtime and size and, when they changed, registers the theme again and
rewrites theme.d.ts. A theme that fails to load answers the request
with its error and is retried on the next one.

Refs #686

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/coordinator.ts 100.00% <100.00%> (ø)
packages/next-plugin/src/css-loader.ts 100.00% <100.00%> (ø)
packages/next-plugin/src/loader.ts 100.00% <100.00%> (ø)
packages/next-plugin/src/plugin.ts 100.00% <100.00%> (ø)

... and 10 files with indirect coverage changes

🚀 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.

coordinator.ts: import both existsSync (main, deleted-source removal from
#951) and statSync (theme stamps). The /extract handler refreshes the theme
first, then records the source for deleted-file removal.

coordinator.test.ts: keep both new describe blocks (theme reload, deleted
sources) side by side.

plugin.ts: keep registerProjectTheme, and write theme.d.ts inside it even
when the interface is empty, as main now does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owjs3901
owjs3901 merged commit eae6f7c into main Nov 17, 2026
27 checks passed
@owjs3901
owjs3901 deleted the fix/next-theme-reload branch November 17, 2026 04:29
owjs3901 added a commit that referenced this pull request Nov 17, 2026
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 added a commit that referenced this pull request Nov 17, 2026
Resolve the coordinator against #944. refreshTheme clears the transform
cache before it reloads the theme, so no extraction cached under the old
theme survives a devup.json change; startCoordinator and resetCoordinator
reset both the cache and the theme watch, and the cache entry of a deleted
file is still dropped. The dependency and theme stamps share one
fileStamp helper. A new test proves a theme reload invalidates the cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Build the Bun source filter with #925's createSourceFilter, whose base now
takes .mts and .cts as this branch does, so included packages keep their .js
files. Merge the README sections, and move #944's Turbopack Tailwind test to
this branch's wider rule glob.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
coordinator.ts: main's Turbopack theme reload (#944) kept its watch in
module globals; it now lives in each app's CoordinatorState, created
from options.theme, and refreshTheme(state) runs before each /css and
/extract of that app. The reload registers the theme through the app's
session compiler, so one app's devup.json never reaches another's
engine. close() writes the pending files synchronously (#917) before
releasing the app, and resetCoordinator keeps clearing the registry
instead of the removed globals. extractor/lib.rs keeps both the
ExtractorCaches export and vanilla_extract_theme_import_tests.

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