Repository navigation
perf(ci): key sandbox next cache by PR to stop cross-basepath invalidation - #3864
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis ReportNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | View full report |
…ation PR builds and main deploys shared one Next.js sandbox cache key, but they build with different basePaths (/<repo>/pr/<n>/sandbox vs /<repo>/sandbox), so Next.js invalidated the restored webpack cache on every PR build: a primary-key hit still compiled for ~4min (run 29181246330) versus 64s for the same key on main (run 29181173652) — the restore was pure download cost. And because the shared key registered as a hit, PRs could never save a cache for their own basePath. Scope the ci.yml key by PR number so each PR warms and reuses its own cache across re-pushes. deploy.yml's key is unchanged, and the no-restore-keys policy (meta#2941) is preserved in both files.
sangwook-dev
force-pushed
the
perf/pr-sandbox-cache-key
branch
from
July 12, 2026 06:34
0e275e6 to
eec0888
Compare
cixzhang
approved these changes
Jul 12, 2026
This branch was successfully deployed
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
The PR
buildjob (ci.yml) and the mainDeploybuild (deploy.yml) share one Next.js sandbox cache key —nextjs-sandbox-<lock hash>-<core dist hash>— but they build with different basePaths: PRs setSANDBOX_BASE_PATH=/<repo>/pr/<n>/sandbox, main sets/<repo>/sandbox. Next.js invalidates its webpack cache whenever the resolved config changes, so the main-built cache that PRs restore is always dead on arrival: the PR pays to download it, then compiles cold anyway.Worse, because the shared key registers as a hit, actions/cache logs
Cache hit occurred on the primary key, not saving— so a PR can never save a cache for its own basePath. Every PR push recompiles the sandbox from scratch, forever.Measured evidence
Same key, same hit — 4.0min on the PR vs 64s on main, and the PR's "hit" is indistinguishable from the cold-cache control. The restored cache is pure download weight on the PR path.
Changes
nextjs-sandbox-pr<n>-<lock hash>-<core dist hash>. Each PR now warms its own cache on the first push and gets real warm rebuilds (~64s-class instead of ~4min) on every subsequent push that doesn't changepackages/core/dist. PR-to-PR sharing is also (correctly) excluded, since every PR has a distinct basePath too.merge_groupfallback is needed in the key: the cache step (and the sandbox build itself) is gated ongithub.event_name == 'pull_request', sogithub.event.pull_request.numberis always set when the key is evaluated.Test plan
yaml.parsevia node); ci key resolves tonextjs-sandbox-pr<n>-<hashes>, deploy key byte-identical to beforehashFiles()emits hex, so main'snextjs-sandbox-<hex>…can never equal a PR'snextjs-sandbox-pr<n>…nextjs-sandbox-pr<n>-…and the sandbox compile drops from ~240s to the ~64s class seen on mainExpected effect: for re-pushes that don't touch core, sandbox compile ~240s → ~64s, cutting ~3min off the PR critical path (stacked with #3811's parallelization, PR CI lands in the ~4min range).