Repository navigation
fix(next-plugin): reload the Turbopack theme when devup.json changes - #944
Merged
Merged
Conversation
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>
8 tasks done
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 10 files with indirect coverage changes 🚀 New features to boost your workflow:
|
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes audit item NXT-11 (P2, WRONG). On Turbopack, the theme was registered only once, while
next.configwas evaluated. Next does not re-readnext.configwhendevup.jsonchanges. 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 duringnext devwas 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.devup.json, the configs itextends(inputsofloadDevupConfigSync), and the project's Tailwind CSS files (findTailwindCss().files).themeFilesis passed in both loaders' options and, in coordinator mode, added withthis.addDependency. When one of these files changes, Turbopack re-runs those loaders.next dev,theme: { files, reload }is passed to the coordinator. Right before/cssand/extract, the coordinator compares the files' mtime / size, and if they changed it re-registers the theme and rewritestheme.d.ts.reloadreturns the new file list, so newly addedextendsare included in later change detection too.registerProjectTheme) that callsfindTailwindCssonly once, producing the same result as the existingwithTailwindCss.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 anextendsfile added later does not re-run the loaders (editingdevup.jsondoes).Overlap with other PRs
fix/next-coordinator-client) moves the coordinator-mode paths ofloader.ts/css-loader.tsintocoordinator-client.ts. This PR only adds one dependency line at the start of each of those paths, so whichever merges later only needs to move them.fix/next-turbo-setup) and fix(plugins): fail production builds on theme errors instead of an empty theme #924 (fix/theme-errors-fail-build) modify theme loading / setup inplugin.ts. In particular, if fix(plugins): fail production builds on theme errors instead of an empty theme #924 changesloadDevupConfigSync's error handling,registerProjectThemegets the same behavior, so theme errors during a dev reload are reported through this PR's "fail the request, then retry" path.Test plan
bun test --coverage(plugin, coordinator, loader, css-loader):plugin.ts,coordinator.ts,loader.ts,css-loader.tsat 100% lines / functionsdevup.jsonis edited, reload on/extractwhen a previously missing extends file appears/cssreturns 500 + message (Error / non-Error),/extractreturns a 500 JSON error, and the next request retriesthemeFilesas dependencies in coordinator modetheme.reloadin the dev coordinator options re-registers the theme and returns the file list; the Tailwind CSS theme and its files are included inthemeFilesbunx tsc --noEmit -p packages/next-pluginbunx prettier --single-quote --no-semi --check(changed files)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 서버를 재시작해야 했습니다.devup.json, 그것이extends하는 config들 (loadDevupConfigSync의inputs), 프로젝트 Tailwind CSS 파일들 (findTailwindCss().files).themeFiles를 넘기고, 코디네이터 모드에서this.addDependency로 추가합니다. 이 파일 중 하나가 바뀌면 Turbopack이 해당 loader들을 다시 실행합니다.next dev에서는 코디네이터에theme: { files, reload }를 넘깁니다. 코디네이터는/css와/extract직전에 파일들의 mtime / size를 비교하고, 바뀌었으면 theme을 다시 등록하고theme.d.ts를 다시 씁니다.reload는 새 파일 목록을 돌려주므로 새로 추가된extends도 이후 변경 감지에 포함됩니다.withTailwindCss와 같은 결과를 내도록findTailwindCss를 한 번만 호출하는 helper(registerProjectTheme)로 묶었습니다.DEVUP_UI_DEFAULT_THEME(config.env)는 setup에서만 정해지므로 기본 theme 이름 변경은 여전히 재시작이 필요합니다. 또 loader 의존성 목록은 setup 시점 기준이라, 나중에 추가된extends파일 편집만으로는 loader가 재실행되지 않습니다 (devup.json편집은 재실행됨).다른 PR과의 겹침
fix/next-coordinator-client)이loader.ts/css-loader.ts의 코디네이터 모드 경로를coordinator-client.ts로 옮깁니다. 이 PR은 그 경로 시작 부분에 의존성 추가 한 줄씩만 넣으므로, 나중에 머지되는 쪽에서 위치만 옮기면 됩니다.fix/next-turbo-setup), fix(plugins): fail production builds on theme errors instead of an empty theme #924 (fix/theme-errors-fail-build)는plugin.ts의 theme 로딩 / setup을 수정합니다. 특히 #924가loadDevupConfigSync의 에러 처리를 바꾸면registerProjectTheme에서도 같은 동작이 되므로, dev reload 중 theme 에러는 이 PR의 "요청 실패 후 재시도" 경로로 보고됩니다.테스트 계획
bun test --coverage(plugin, coordinator, loader, css-loader):plugin.ts,coordinator.ts,loader.ts,css-loader.ts100% lines / functionsdevup.json수정 시 한 번만 reload, 없던 extends 파일이 생기면/extract에서 reload/css는 500 + 메시지 (Error / non-Error),/extract는 500 JSON 에러, 다음 요청에서 재시도themeFiles를 dependency로 추가theme.reload가 theme을 다시 등록하고 파일 목록을 반환, Tailwind CSS theme과 그 파일들이themeFiles에 포함bunx tsc --noEmit -p packages/next-pluginbunx prettier --single-quote --no-semi --check(변경 파일)plugin.test.ts의 3개 테스트(native 엔진 /seedFileMap)는 오래된 WASM / native 빌드 때문에 main에서도 동일하게 실패합니다.Refs #686
🤖 Generated with Claude Code