Repository navigation
perf(next-plugin): cache the coordinator's latest extraction per file - #946
Merged
Merged
Conversation
Next compiles a module that both the server and the client graph import once per graph, with the same source. In next dev nothing was prewarmed, so every /extract ran the engine again and rewrote the CSS and state files even though the styles were already in the sheet. The coordinator now keeps the latest extraction of each file with its source, CSS directory and the mtime and size of the files the extraction read through the module resolver. A request with the same source and CSS directory whose dependencies are unchanged is answered from it and, like a prewarm hit, writes nothing. Only the latest source per file is kept, so the cache is bounded by the file count and a hit always means the sheet holds exactly that source's styles; going back to an earlier source extracts again. A failing extraction drops the file's entry. Refs #686 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This was referenced Nov 15, 2026
coordinator.ts: import both existsSync (main, deleted-source removal from #951) and statSync (dependency stamps). When main's removeDeletedSources forgets a deleted file, it now drops that file's transform cache entry too: the file's styles leave the sheet, so a restored file with the same source must extract again instead of answering from the cache. coordinator.test.ts: keep both new describe blocks (transform cache, deleted sources), and add a test that a deleted file restored unchanged is extracted again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Resolve the conflict with #946 in packages/next-plugin/src/coordinator.ts. The transform cache becomes per app: it lives in each app's CoordinatorState next to extractedSources, a theme refresh clears only that app's cache, and a removed source drops only the owning app's entry. themeStamp is replaced by #946's fileStamp. Adds a test that two apps never share cached extractions. 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
Fix for audit item NXT-13 (P2, PERF). Next compiles a module imported by both the server graph and the client graph once per graph, with the same source, in no guaranteed order.
next devhas no prewarm results, so the second/extractalso re-ran WASM every time and rewrote the CSS / state files, even though the styles were already in the sheet.relCssDir)dependencies)startCoordinator/resetCoordinator.Overlap with other PRs
refreshTheme()now callstransformCache.clear()once a theme input has changed, before the reload (a reload that throws may already have changed the registered theme).startCoordinator/resetCoordinatorreset both the cache and the theme watch, and the dependency and theme stamps share onefileStamphelper.coordinator.ts(wait function / final write), so only textual conflicts are possible.Test plan
bun test --coverage src/__tests__/coordinator.test.ts:coordinator.ts100% lines / functionstransformCache.clear()inrefreshThemeis removed)plugin.test.ts,loader.test.tsbunx tsc --noEmit -p packages/next-pluginbunx prettier --single-quote --no-semi --check(changed files)요약
감사 항목 NXT-13 (P2, PERF) 수정입니다. Next는 server 그래프와 client 그래프가 모두 import하는 모듈을 그래프마다 한 번씩, 같은 소스로, 순서 보장 없이 컴파일합니다.
next dev에는 prewarm 결과가 없으므로 두 번째/extract도 매번 WASM을 다시 실행하고 CSS / state 파일을 다시 썼습니다. 스타일은 이미 시트에 들어 있는데도 그랬습니다.relCssDir)dependencies)의 mtime / sizestartCoordinator/resetCoordinator에서 비웁니다.다른 PR과의 겹침
refreshTheme()가 reload 전에transformCache.clear()를 호출합니다 (예외를 던진 reload도 등록된 theme을 이미 바꿨을 수 있기 때문).startCoordinator/resetCoordinator는 캐시와 theme watch를 함께 초기화하고, dependency와 theme stamp는 하나의fileStamp헬퍼를 공유합니다.coordinator.ts의 다른 부분(대기 함수 / 종료 쓰기)을 수정하므로 텍스트 충돌만 가능합니다.테스트 계획
bun test --coverage src/__tests__/coordinator.test.ts:coordinator.ts100% lines / functionsrefreshTheme의transformCache.clear()를 빼면 실패)plugin.test.ts,loader.test.tsbunx tsc --noEmit -p packages/next-pluginbunx prettier --single-quote --no-semi --check(변경 파일)Refs #686
🤖 Generated with Claude Code