Skip to content

fix(cloudflare): read v1 Build Output alongside v0 - #4704

Merged
james-elicx merged 5 commits into
mainfrom
fix/cloudflare-build-output-v1
Nov 14, 2026
Merged

james-elicx merged 5 commits into
mainfrom
fix/cloudflare-build-output-v1

Conversation

@james-elicx

@james-elicx james-elicx commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

The typed cf deploy flow hardcoded .cloudflare/output/v0 when locating the generated default Worker, so a Build Output written under v1 would be missed.

Changes

  • Add packages/cloudflare/src/build-output.ts, which resolves the versioned Build Output directory (v0, v1, …). Like cf's Build Output reader (@cloudflare/build-output-utils), it rejects output in more than one version with "Delete .cloudflare/output and rebuild" rather than guessing between them. Builds clean the whole .cloudflare/output, so this only happens with leftover or hand-copied output. With no version directory it returns the v0 path, so existing missing-build errors are unchanged.
  • Use it everywhere the v0 path was hardcoded or scanned:
    • deploy.ts: the Worker bundle and assets directories for prerendering, and the version-metadata check before CDN warmup.
    • tpr.ts: reading domains from the Worker config (typed configs only). This also accepts object domains ({ hostname, production, previews }) and picks the first production one.
    • version-deploy.ts: reading the Worker name.
    • cacheability-artifact.ts: locating the Worker config for two-stage CDN warming.
  • The CI and create-app deploy workflows now use v1 when v1/workers/default/worker.config.json exists and fall back to v0.
  • Tests that read real cf build output now go through the helper. Tests that write their own v0 files are unchanged and still cover v0.

Tests

  • New unit tests: v1 Build Output for prerender dirs, the Worker name, and the cacheability manifest; rejection when both v0 and v1 exist; production object domains for TPR.
  • vp test run on tests/deploy.test.ts, tests/cloudflare-version-deploy.test.ts, tests/cloudflare-cdn-warm-deploy.test.ts, tests/tpr-routes.test.ts and tests/deploy-prerender-config.test.ts: all pass.
  • vp check is clean on the changed files.

No build or dev runtime code is touched, so there are no perf numbers here.

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head 32592bd05388b1781bb07d9dc50aa45afc8d5c95 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vinext/cloudflare

npm i https://pkg.pr.new/@vinext/cloudflare@4704

create-vinext-app

npm i https://pkg.pr.new/create-vinext-app@4704

@vinext/types

npm i https://pkg.pr.new/@vinext/types@4704

vinext

npm i https://pkg.pr.new/vinext@4704

@cloudflare/workers-response-store

npm i https://pkg.pr.new/@cloudflare/workers-response-store@4704

commit: 83cb25e

Comment thread packages/cloudflare/src/tpr.ts Outdated
root,
".cloudflare/output/v0/workers/default/worker.config.json",
);
const buildOutputConfigPath = resolveBuildOutputDefaultWorkerConfigPath(root);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[warning] v1 Worker configs allow domains entries such as { hostname, production, previews }, but the extraction below accepts only strings. A valid v1 config using a production-enabled object therefore falls through to no custom domain and silently disables traffic-aware warming. Please normalize both schema forms (and select an object enabled for production). The v1 schema is defined in cloudflare/workers-sdk#16917 (DomainSchema).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a9a291e: TPR now takes the first string domain or the first object domain with production: true, with a test covering the object form.

@ask-bonk

ask-bonk Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Review: 1 finding.

Posted 1 actionable inline comment.

github run

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared 83cb25e against base 5c6b161 using alternating same-runner rounds. Next.js was unchanged and skipped.

2 improved · 0 regressed · 5 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 152.4 KB 152.4 KB ⚫ 0.0%
Client entry size (gzip) vinext 140.7 KB 140.7 KB ⚫ 0.0%
Dev server cold start vinext 1.92 s 1.86 s 🟢 -2.9%
Dev server cold start (large Pages Router app) vinext 14.29 s 14.03 s 🟢 -1.8%
Production build time vinext 2.16 s 2.16 s ⚫ +0.1%
RSC entry closure size (gzip) vinext 142.7 KB 142.7 KB ⚫ 0.0%
Server bundle size (gzip) vinext 250.4 KB 250.4 KB ⚫ +0.0%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

@github-actions

Copy link
Copy Markdown
Contributor
Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original
response-store-demo preview production
workers-cache preview production
kv preview production
static-assets-cache preview production
static-assets-pages preview production
static-assets-pages-i18n preview production
static-export preview production
web preview production

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head a9a291e36465bf509e4075163995bda3a710fb67 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@ask-bonk

ask-bonk Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

@james-elicx
james-elicx marked this pull request as ready for review November 13, 2026 20:58

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of b1e77cab.

This review, of a9a291e3

💬 Approved with comments — The change is correct and well scoped. There is one INFO note about a mismatch with the cacheability scanner when both output versions exist, and one optional SUGGESTION to align the CI check with the helper.

Findings: 1 info · 1 suggestion (2 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info · 1 suggestion

The helper is used consistently. Two minor consistency notes.

Recommendation: 💬 Optional Nits

  • [INFO] The helper picks v1 when both versions have a default Worker config, but cacheability-artifact.ts throws unless exactly one does. (packages/cloudflare/src/build-output.ts:14)
  • [SUGGESTION] The CI check uses test -d v1, but the helper checks for v1/workers/default/worker.config.json. (.github/workflows/ci.yml:462)
View full review
  • Dual-version output (INFO). resolveBuildOutputDir prefers v1 when both v0 and v1 have a default Worker config. resolveBuildOutputArtifact in cacheability-artifact.ts:189-204 throws unless exactly one version has one, so two-stage CDN warming still fails if a stale v0 sits next to a fresh v1. That was already true before this change. Consider sharing one resolver, or documenting that output with both versions is unsupported.
  • Workflow check vs helper (SUGGESTION). The workflows choose v1 with test -d, but the helper requires v1/workers/default/worker.config.json. Checking for that file in the workflows would make them select the same directory as the helper.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found in the Build Output path resolution or the domain parsing.


📖 AGENTS.md: ✅ LGTM

Nothing in this pull request needs a change to the agent guidelines.


⚡ Performance: ✅ LGTM

No performance concerns. The new code is a few deploy-time existence checks.


📝 Documentation: ✅ LGTM

The new helper is documented clearly.


Reviewed commit: a9a291e3

Comment thread packages/cloudflare/src/build-output.ts Outdated
*/
export function resolveBuildOutputDir(root: string): string {
const outputDir = path.join(root, ".cloudflare", "output");
for (const version of BUILD_OUTPUT_VERSIONS) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ INFO · Code Quality

The helper picks v1 when both versions have a default Worker config, but cacheability-artifact.ts throws unless exactly one does.

If v0 and v1 both have workers/default/worker.config.json (say a stale v0 left behind after an upgrade), this resolver returns v1. resolveBuildOutputArtifact in cacheability-artifact.ts still requires exactly one such config, so two-stage CDN warming throws in that state. That was already the case before this change. Consider having the scanner use this resolver, or documenting that output with both versions is unsupported.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b1e77ca: cacheability-artifact.ts now uses the shared resolver, so a stale v0 next to v1 resolves to v1 there too, with a test.

Comment thread .github/workflows/ci.yml Outdated
test -f .cloudflare/output/v0/workers/default/worker.config.json
test -f .cloudflare/output/v0/workers/cva-cloudflare-response-store/worker.config.json
OUTPUT_DIR=.cloudflare/output/v1
test -d "$OUTPUT_DIR" || OUTPUT_DIR=.cloudflare/output/v0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 SUGGESTION · Code Quality

The CI check uses test -d v1, but the helper checks for v1/workers/default/worker.config.json.

The helper treats v1 as present only when workers/default/worker.config.json exists, but this check accepts any v1 directory. An empty or partial v1 next to a complete v0 would make this step assert against v1 and fail, while the deploy code would use v0. Testing for the worker config file here (and in the create-app workflows) would keep the two in sync.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b1e77ca: all three workflows now pick v1 only when v1/workers/default/worker.config.json exists.

@james-elicx

Copy link
Copy Markdown
Member Author

clanky review

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head b1e77cab34d851593232c4be05397a46fe152682 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 4b65f074.

This review, of b1e77cab

✅ Approved — Both earlier notes are fixed at b1e77ca and no new issues were found in the changed code.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues found in the Build Output path resolution, the domain parsing or the workflow changes.


📖 AGENTS.md: ✅ LGTM

Nothing in this pull request needs a change to the agent guidelines.


📋 Code Quality: ✅ LGTM

Both earlier notes are fixed. cacheability-artifact.ts now uses the shared resolver, and the workflows check for v1/workers/default/worker.config.json before choosing v1. When neither version has a config, the code still falls back to v0, so a missing build reports the same errors as before.


⚡ Performance: ✅ LGTM

No performance concerns. The new code adds only a few file-existence checks at deploy time.


📝 Documentation: ✅ LGTM

The new helper is documented clearly.


Reviewed commit: b1e77cab

@ask-bonk

ask-bonk Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Review: 1 findings.

  • Warning packages/cloudflare/src/build-output.ts:14: Preferring v1 when both versions exist disagrees with cf. Current cf reads only v0; the upcoming v1 reader explicitly rejects multiple version directories. Thus warm deploys may mutate/read v1 while deploying v0. Reject multiple versions instead of selecting the newest.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head 4b65f0746881c102e27bfaa47e91ab88052c1bc1 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 83cb25ea.

This review, of 4b65f074

✅ Approved — No issues found in the code changed since the last review. Multi-version Build Output is rejected consistently, and production object domains are handled correctly.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues in the path resolution, the domain parsing or the workflow changes.


📖 AGENTS.md: ✅ LGTM

Nothing in this pull request needs a change to the agent guidelines.


📋 Code Quality: ✅ LGTM

The resolver falls back to v0 and rejects output in more than one version. findProductionDomain handles string and production object domains, and falls back to the wrangler custom domain otherwise. The new tests cover v1 output, the multi-version rejection and object domains.


⚡ Performance: ✅ LGTM

The change adds only a single directory read at deploy time.


📝 Documentation: ✅ LGTM

The new helper's JSDoc describes the fallback and the multi-version rejection accurately.


Reviewed commit: 4b65f074

Comment thread packages/cloudflare/src/build-output.ts Outdated
`Found Cloudflare Build Output in more than one format (${versions.join(", ")}) in ${outputDir}. Delete ${outputDir} and rebuild.`,
);
}
return path.join(outputDir, versions[0] ?? "v0");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[warning] A sole v2 (or any future vN) directory is returned as usable even though this code only understands the v0/v1 workers/default layout and config schema. Build Output explicitly guarantees only the v<N> directory naming convention; everything inside is version-specific, and Cloudflare's v1 readBuildOutput() rejects newer versions. This can make vinext read or rewrite an incompatible bundle before cf rejects it. Please allow only v0 and v1 here and throw for any other detected version. Reference: https://github.com/cloudflare/workers-sdk/blob/b8ae10f9b4c31d50b55a05cf87d397f9d00f3948/packages/build-output-utils/src/read.ts#L178-L232

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 83cb25e: a sole version other than v0/v1 is now rejected with an upgrade error, with a test.

.readdirSync(outputDir, { withFileTypes: true })
.filter(
(entry) =>
(entry.isDirectory() || entry.isSymbolicLink()) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[warning] A sole version symlink is accepted and every caller follows it; the cacheability path can then write modules through that link outside the Build Output tree. Cloudflare's reader counts version symlinks during detection only so its subsequent symlink validation rejects them, and it also rejects linked .cloudflare/output paths. Reject linked path components before returning this directory so --warm-cache cannot mutate linked content before cf fails. Reference: https://github.com/cloudflare/workers-sdk/blob/b8ae10f9b4c31d50b55a05cf87d397f9d00f3948/packages/build-output-utils/src/read.ts#L234-L286

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 83cb25e: a symlinked version directory, .cloudflare or output is now rejected before any caller reads or writes through it, with tests.

@ask-bonk

ask-bonk Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Review: 2 findings.

Posted 2 actionable inline comments.

github run

@james-elicx

Copy link
Copy Markdown
Member Author

/bigbonk review for issues
Please review exact head 83cb25eabde0f0221cb831c1cab550f05f0dcb5d without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — No issues in the code changed since the last review. Symlinked, unsupported-version and multi-version Build Output are all rejected consistently, and the new tests cover each case.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

A linked .cloudflare, output or version directory is rejected before any caller reads or writes through it, including the cacheability artifact path that writes modules.


📖 AGENTS.md: ✅ LGTM

Nothing in this pull request needs a change to the agent guidelines.


📋 Code Quality: ✅ LGTM

resolveBuildOutputDir uses lstat to reject a symlinked .cloudflare or output. It also rejects a symlinked version directory, because Dirent.isSymbolicLink() does not follow links. Output in more than one version is rejected before the v0/v1 check, and a lone unsupported version fails with an upgrade error. With no version directory it still falls back to v0. The new tests in tests/deploy.test.ts cover v2, a symlinked v1 and a symlinked .cloudflare.


⚡ Performance: ✅ LGTM

The resolver adds a few lstat/stat calls and one small readdir, and only at deploy time.


📝 Documentation: ✅ LGTM

The JSDoc on resolveBuildOutputDir correctly describes the v0 fallback and the rejection of multi-version, unsupported and linked output.


Reviewed commit: 83cb25ea

@ask-bonk

ask-bonk Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Review: 1 findings.

  • Warning packages/cloudflare/src/build-output.ts:48: Nested symlinks remain accepted. A linked v1/workers/default/bundle lets cacheability-artifact.ts:328 write outside Build Output before cf validates it. Recursively reject symlinks within the selected version directory, matching Cloudflare’s reader.

github run

@james-elicx
james-elicx merged commit a87070f into main Nov 14, 2026
109 checks passed
@james-elicx
james-elicx deleted the fix/cloudflare-build-output-v1 branch November 14, 2026 00:45
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