Skip to content

[wrangler] fix: warn when named env silently inherits custom_domain routes#13979

Merged
petebacondarwin merged 8 commits into
cloudflare:mainfrom
matingathani:fix/warn-custom-domain-route-inheritance
Jun 3, 2026
Merged

[wrangler] fix: warn when named env silently inherits custom_domain routes#13979
petebacondarwin merged 8 commits into
cloudflare:mainfrom
matingathani:fix/warn-custom-domain-route-inheritance

Conversation

@matingathani

@matingathani matingathani commented May 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #13925.

When an env.<name> block does not override routes, it inherits the top-level routes array. If that array contains entries with custom_domain: true, every deploy to the named environment silently reassigns the custom domain away from the top-level Worker, causing routing drift that is very hard to diagnose.

Changes

  • Modified validateRoutes() in packages/workers-utils/src/config/validation.ts to emit a warning when:
    • A named environment is active (not the top-level env)
    • The env block doesn't define its own routes
    • The inherited top-level routes contains at least one { custom_domain: true } entry
  • Warning message names the custom domain(s) and suggests adding "routes": [] to the env block to prevent inheritance

Example warning

▲ [WARNING] Processing wrangler.toml configuration:

    - "env.staging" environment configuration
      - The "env.staging" environment inherits the top-level `routes` configuration, which includes
        the custom domain(s): api.example.com. Deploying this environment will reassign these custom
        domains away from the top-level Worker. Add `"routes": []` to "env.staging" to prevent
        inheritance.

  • Tests
    • Tests included/updated
  • Public documentation
    • Documentation not necessary because: this is a warning for an existing undocumented footgun; no public API or CLI flags changed

Open in Devin Review

Copilot AI review requested due to automatic review settings May 20, 2026 05:11
@changeset-bot

changeset-bot Bot commented May 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5cd92bd

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

This PR includes changesets to release 3 packages
Name Type
wrangler 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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk May 20, 2026
@workers-devprod workers-devprod requested review from a team and emily-shen and removed request for a team May 20, 2026 05:11
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/warn-custom-domain-route-inheritance.md: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/validation.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/config/configuration.test.ts: [@cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

This comment was marked as resolved.

@pkg-pr-new

pkg-pr-new Bot commented May 20, 2026

Copy link
Copy Markdown
create-cloudflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/create-cloudflare@13979

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/deploy-helpers@13979

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/kv-asset-handler@13979

miniflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/miniflare@13979

@cloudflare/pages-shared

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/pages-shared@13979

@cloudflare/unenv-preset

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/unenv-preset@13979

@cloudflare/vite-plugin

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/vite-plugin@13979

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

npm i https://pkg.pr.new/cloudflare/workers-sdk/wrangler@13979

@cloudflare/wrangler-bundler

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/wrangler-bundler@13979

commit: 5cd92bd

@matingathani matingathani force-pushed the fix/warn-custom-domain-route-inheritance branch from 64b1a77 to 3aaa4ed Compare May 20, 2026 14:06
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/warn-custom-domain-route-inheritance.md: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/validation.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/config/configuration.test.ts: [@cloudflare/wrangler]

@petebacondarwin petebacondarwin 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.

Small suggestion, giving the user the option of hiding the warning.

Comment thread packages/workers-utils/src/config/validation.ts Outdated
@github-project-automation github-project-automation Bot moved this from Untriaged to In Review in workers-sdk Jun 1, 2026
@workers-devprod

workers-devprod commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@petebacondarwin petebacondarwin requested review from petebacondarwin and removed request for emily-shen June 3, 2026 08:35
@petebacondarwin petebacondarwin force-pushed the fix/warn-custom-domain-route-inheritance branch from f2ad31a to 9fac7c6 Compare June 3, 2026 08:36

@workers-devprod workers-devprod 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.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from In Review to Approved in workers-sdk Jun 3, 2026
…outes

When an env block does not override `routes`, it inherits the top-level
routes array. If that array contains custom_domain:true entries, each
deploy to the named env reassigns the custom domain away from the
top-level Worker, causing routing drift.

Wrangler now emits a warning in this situation and suggests adding
`"routes": []` to the env block to prevent inheritance.

Fixes cloudflare#13925
- Remove conventional commit prefix from changeset title (violates AGENTS.md rule)
- Make envName optional in validateRoutes (undefined = top level) to avoid magic string sentinel
- Use topLevelEnv === undefined to detect top-level env at call site (cleaner than string comparison)
- Simplify customDomains map with a type predicate to eliminate redundant type checks
Import CustomDomainRoute and use it directly in the type predicate to
fix TS2677 error. CustomDomainRoute has `custom_domain: boolean` (required)
and `pattern: string`, satisfying the type predicate constraint.
… custom domain inheritance warning

Refactor the custom domain check to filter once into a variable rather than
scanning the routes array twice. The `r !== null` guard is redundant alongside
`typeof r === "object"` but harmless; keeping it satisfies the type predicate.
Add "or copy the route configuration from the top level to hide this
warning." to the custom domain inheritance warning, so users have
two actionable choices (suppress via empty routes, or explicitly copy).
@matingathani matingathani force-pushed the fix/warn-custom-domain-route-inheritance branch from 9fac7c6 to 78307a6 Compare June 3, 2026 09:13
@petebacondarwin

Copy link
Copy Markdown
Contributor

@matingathani - unfortunately the formatting is off

@petebacondarwin petebacondarwin merged commit c2280cd into cloudflare:main Jun 3, 2026
52 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jun 3, 2026
@matingathani

Copy link
Copy Markdown
Contributor Author

Fixed the formatting in 44bfd4f.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[bug] routes inheritance silently transfers ownership of custom domains between env Workers on every deploy

4 participants