Skip to content

[wrangler] Surface _redirects validation warnings at deploy time (#14694)#14709

Open
allocsys wants to merge 12 commits into
cloudflare:mainfrom
allocsys:fix/14694-redirects-deploy-warning
Open

[wrangler] Surface _redirects validation warnings at deploy time (#14694)#14709
allocsys wants to merge 12 commits into
cloudflare:mainfrom
allocsys:fix/14694-redirects-deploy-warning

Conversation

@allocsys

@allocsys allocsys commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #14694

What this PR solves

Wrangler's deploy-time _redirects validation didn't respect assets.html_handling when checking for infinite-loop redirect rules. This caused a false "infinite loop" warning for setups like html_handling: "none" with a rule such as / /index.html, since the validator didn't account for HTML handling being disabled.

Fix

parseRedirects() in resolveAssetOptions() now passes htmlHandling: config.assets?.html_handling, matching the behavior already used by the Vite plugin (packages/vite-plugin-cloudflare/src/asset-config.ts).

Tests

  • Tests included/updated
    • html_handling: "none" + a rule like / /index.html no longer produces a false "infinite loop" warning at deploy time
    • The same rule with default HTML handling is still correctly flagged as an infinite loop, confirming detection isn't weakened

Documentation

  • Documentation not necessary because: this fixes a bug in existing validation logic; no new user-facing behavior or config surface is introduced

@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 175cf65

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
wrangler Patch
@cloudflare/workers-shared Patch
@cloudflare/deploy-helpers Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@allocsys allocsys changed the title Surface _redirects validation warnings at wrangler deploy time (#14694) [wrangler] Surface _redirects validation warnings at deploy time (#14694) Jul 15, 2026
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/deploy-config
  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/warm-redirects-deploy-warning.md: [@cloudflare/wrangler]
  • packages/deploy-helpers/src/deploy/helpers/assets.ts: [@cloudflare/wrangler]
  • packages/workers-shared/utils/configuration/constructConfiguration.ts: [@cloudflare/deploy-config @cloudflare/wrangler]
  • packages/wrangler/src/tests/deploy/assets.test.ts: [@cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

allocsys added 2 commits July 16, 2026 00:26
…udflare#14694 review comment)

config.assets?.html_handling was already available in this function but wasn't threaded through to the new deploy-time parseRedirects() call, so htmlHandling defaulted to undefined -- which parseRedirects treats as "enabled" -- causing false "infinite loop detected" warnings for users who set html_handling: "none" on rules like `/ /index.html`. Now passes the same option the Vite plugin already passes correctly.
…infinite-loop warning at deploy time

Covers the review finding on cloudflare#14709 -- parseRedirects() previously ran with htmlHandling always undefined at deploy time (treated as enabled), so a rule like `/ /index.html` was flagged as an infinite loop even for projects that explicitly disabled HTML handling. Adds a test confirming no warning is produced now that config.assets?.html_handling is threaded through, plus a sanity check that the real infinite-loop case is still caught when HTML handling is left at its default.
@allocsys

Copy link
Copy Markdown
Contributor Author

Fixed in 018173cparseRedirects() in resolveAssetOptions() now passes htmlHandling: config.assets?.html_handling, matching what the Vite plugin already does at packages/vite-plugin-cloudflare/src/asset-config.ts.

Added two regression tests in 627a9d2:

  • html_handling: "none" + a rule like / /index.html no longer produces a false "infinite loop" warning at deploy time.
  • The same rule with HTML handling left at its default is still correctly flagged as an infinite loop, so the real detection isn't weakened.

Both commits are pushed to this PR's branch. Thanks for catching this!

Comment on lines +10 to +12
`wrangler deploy` now parses `_redirects` for validation purposes and warns about any invalid rules, using the same messages already shown by `wrangler dev`. This does not change what gets uploaded — the raw file is still uploaded as-is, and the asset worker remains the authoritative parser at runtime.

<!-- trigger fork CI -->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This comment can be removed

Suggested change
`wrangler deploy` now parses `_redirects` for validation purposes and warns about any invalid rules, using the same messages already shown by `wrangler dev`. This does not change what gets uploaded — the raw file is still uploaded as-is, and the asset worker remains the authoritative parser at runtime.
<!-- trigger fork CI -->
`wrangler deploy` now parses `_redirects` for validation purposes and warns about any invalid rules, using the same messages already shown by `wrangler dev`. This does not change what gets uploaded — the raw file is still uploaded as-is, and the asset worker remains the authoritative parser at runtime.

expect(std.warn).toMatchInlineSnapshot(`""`);
});

it("should warn about invalid _redirects rules at deploy time without altering what is uploaded (#14694)", async ({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We probably don't need the issue reference in the title of this test name.

Suggested change
it("should warn about invalid _redirects rules at deploy time without altering what is uploaded (#14694)", async ({
it("should warn about invalid _redirects rules at deploy time without altering what is uploaded", async ({

expect(std.warn).toContain("Ignoring duplicate rule for path /foo.");
});

it("should not warn about a false infinite-loop when html_handling is 'none' (#14709 review)", async ({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
it("should not warn about a false infinite-loop when html_handling is 'none' (#14709 review)", async ({
it("should not warn about a false infinite-loop when html_handling is 'none'", async ({

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14709

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@14709

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14709

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14709

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14709

miniflare

npm i https://pkg.pr.new/miniflare@14709

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14709

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14709

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14709

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14709

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14709

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14709

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14709

wrangler

npm i https://pkg.pr.new/wrangler@14709

commit: 627a9d2

@NuroDev NuroDev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you also update the PR description to reflect the repository template so we have details on tests, docs, etc.

@github-project-automation github-project-automation Bot moved this from Untriaged to In Review in workers-sdk Jul 16, 2026
@allocsys

Copy link
Copy Markdown
Contributor Author

Thanks @NuroDev — addressed all three:

  • Removed the leftover <!-- trigger fork CI --> comment from .changeset/warm-redirects-deploy-warning.md (4ef9ffe).
  • Dropped the (#14694) and (#14709 review) issue references from the two test names in assets.test.ts (90ed703).

@devin-ai-integration devin-ai-integration Bot left a comment

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.

Devin Review found 1 new potential issue.

Open in Devin Review

Comment on lines +567 to +579
if (_redirects) {
const parsedRedirects = parseRedirects(_redirects, {
htmlHandling: config.assets?.html_handling,
});
if (parsedRedirects.invalid.length > 0) {
logger.warn(
formatInvalidRedirectsWarning(
parsedRedirects.invalid,
REDIRECTS_FILENAME
)
);
}
}

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.

🟡 Invalid redirect-file warnings shown twice during local development

Redirect-file validation warnings are now emitted inside a shared resolution step (parseRedirects/logger.warn at packages/deploy-helpers/src/deploy/helpers/assets.ts:567-579) that also runs during local development, where the same warnings are already produced separately, so a developer sees each invalid-redirect warning twice.
Impact: During wrangler dev (and in preview / platform-proxy tooling), users get duplicate and unexpected warnings about invalid _redirects rules that previously appeared only once.

Why the shared code path double-fires the warning

The new block was added to resolveAssetOptions() in packages/deploy-helpers/src/deploy/helpers/assets.ts:567-579. That function is not deploy-only: packages/wrangler/src/assets.ts:132 (getAssetsOptions) calls it, and getAssetsOptions is invoked from the dev config resolver packages/wrangler/src/api/startDevWorker/ConfigController.ts:375, from packages/wrangler/src/preview/commands.ts:51, and from packages/wrangler/src/api/integrations/platform/index.ts (getPlatformProxy).

In wrangler dev, DevEnv.startWorker first calls initDeployHelpersContext (packages/wrangler/src/api/startDevWorker/DevEnv.ts:41) so the deploy-helpers logger routes to wrangler's logger, then this.config.set(...) runs ConfigController, which calls getAssetsOptionsresolveAssetOptions, emitting the invalid-redirect warning. Separately, Miniflare's asset plugin parses the same _redirects file and emits the identical warning via constructRedirects (packages/miniflare/src/plugins/assets/index.ts:150-159). The result is two copies of the warning for every invalid rule. Before this PR resolveAssetOptions did not parse _redirects, so dev showed the warning only once.

Prompt for agents
The new _redirects validation warning was added to resolveAssetOptions() in packages/deploy-helpers/src/deploy/helpers/assets.ts (lines 567-579). resolveAssetOptions is a shared function: it is called via packages/wrangler/src/assets.ts getAssetsOptions(), which runs not only in the deploy/versions-upload paths but also during wrangler dev (packages/wrangler/src/api/startDevWorker/ConfigController.ts around line 375), preview (packages/wrangler/src/preview/commands.ts), and getPlatformProxy (packages/wrangler/src/api/integrations/platform/index.ts). During wrangler dev, Miniflare's assets plugin already parses _redirects and emits the same invalid-rule warnings via constructRedirects (packages/miniflare/src/plugins/assets/index.ts around line 150). As a result, the new code causes the same warnings to be printed twice in local dev (and also surfaces them unexpectedly in preview/platform-proxy contexts). The intent of the PR is to surface these warnings only at deploy time. Consider gating the validation so it only runs on the deploy/versions-upload path — e.g. move the parse-and-warn logic out of the shared resolveAssetOptions into the deploy-specific callers (deploy.ts / versions-upload.ts), or add an explicit opt-in parameter to resolveAssetOptions that only the deploy paths pass. Ensure the existing deploy tests still pass and that dev no longer double-warns.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

devin-ai-integration[bot]

This comment was marked as resolved.

… appears in the wrangler changelog, per Devin review feedback on PR cloudflare#14709
@allocsys

Copy link
Copy Markdown
Contributor Author

Good catch — fixed in 175cf65. wrangler now bumped directly in the changeset so this gets a descriptive changelog entry instead of an opaque dependency-bump line.

@allocsys

Copy link
Copy Markdown
Contributor Author

@NuroDev The PR description now includes the Tests and Documentation sections from the template — could you take another look when you get a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

_redirects: dynamic-rule overflow silently drops rest of file; static/dynamic classification is order-dependent and unsurfaced

3 participants