Skip to content

run_worker_first support in wrangler #9509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 11, 2025
Merged

Conversation

emily-shen
Copy link
Contributor

@emily-shen emily-shen commented Jun 6, 2025

Supersedes #9304

Follows on from #9416


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • Wrangler / Vite E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: done separately
  • Wrangler V3 Backport
    • TODO (before merge)
    • Wrangler PR:
    • Not necessary because: new feat

@emily-shen emily-shen requested review from a team as code owners June 6, 2025 12:22
Copy link

changeset-bot bot commented Jun 6, 2025

🦋 Changeset detected

Latest commit: 79c6ce9

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

This PR includes changesets to release 5 packages
Name Type
miniflare Minor
wrangler Minor
@cloudflare/pages-shared 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

@workers-devprod workers-devprod added e2e Run wrangler + vite-plugin e2e tests on a PR c3-e2e Run c3 e2e tests on a PR labels Jun 6, 2025
@emily-shen emily-shen changed the title Emily/routes plumbing take 2 run_worker_first support in wrangler dev Jun 6, 2025
@emily-shen emily-shen changed the base branch from main to pr/matthewdavidrodgers/9416 June 6, 2025 12:31
@emily-shen emily-shen changed the base branch from pr/matthewdavidrodgers/9416 to main June 6, 2025 12:31
@emily-shen emily-shen force-pushed the emily/routes-plumbing-take-2 branch 2 times, most recently from fa21799 to d4ca6c7 Compare June 6, 2025 15:58
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jun 6, 2025
Copy link

pkg-pr-new bot commented Jun 6, 2025

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

wrangler

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

commit: 79c6ce9

@emily-shen emily-shen changed the title run_worker_first support in wrangler dev run_worker_first support in wrangler Jun 6, 2025
@emily-shen emily-shen force-pushed the emily/routes-plumbing-take-2 branch from 3916678 to 0ec5888 Compare June 8, 2025 13:47
Copy link
Contributor

@jamesopstad jamesopstad left a comment

Choose a reason for hiding this comment

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

Various minor comments but looks good!

if (assets?.routerConfig?.static_routing) {
const rawAssetConfig =
assets.routerConfig.static_routing.asset_worker?.map(
// unparse this for upload :(
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem ideal. Why does Wrangler need to split the original array except for local dev?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, this is definitely not ideal :(

I put it here as remote dev and deploy both need it, but on reflection its probably easier to just pass the whole thing through even if its redundant in dev (cec7cc0).

it would be good to disentangle dev asset options and upload asset options entirely, but probably best for a followup PR

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Jun 9, 2025
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Nice work. Just a bunch of nits and queries

import { parseStaticRouting } from "../configuration/parseStaticRouting";

describe("parseStaticRouting", () => {
it("throws when given empty rules", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

OOC - why throw an error for some invalid rules but return an object containing {errors} for other invalid rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

partially because i'm just copying EWC's validation exactly.
but also the ones that throw are 'general' errors, and the ones that we collect are rule-specific errors.

expect(errorMessage).toMatchInlineSnapshot(
`
"Invalid routes in run_worker_first:
'/api/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': all rules must be less than 100 characters in length"
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting note: the ! of negative rules does not count towards the maximum size, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, since i don't think we store them with the ! - @matthewdavidrodgers is this right?

Comment on lines +446 to +459
if (typeof config.assets?.run_worker_first === "boolean") {
routerConfig.invoke_user_worker_ahead_of_assets =
config.assets.run_worker_first;
} else if (Array.isArray(config.assets?.run_worker_first)) {
const { parsed, errorMessage } = parseStaticRouting(
config.assets.run_worker_first
);
if (errorMessage) {
throw new UserError(errorMessage, {
telemetryMessage: "invalid run_worker_first rules",
});
}
routerConfig.static_routing = parsed;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering if it would simplify things in miniflare, wrangler dev and vite dev if parseStaticRouting received the run_worker_first value directly and treated true as an alias for { parsed: { user_worker: ["/*"] }}? That way we wouldn't need to worry about the invoke_user_worker_ahead_of_assets value. false could return { parsed: undefined }. No big deal if not. This only changes the internals so we could always do this later. cc @petebacondarwin.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is likely that the internal implementation of run_worker_first: true is simplified (i.e. no need to do any pattern matching at all), so I am hesitant to say we should alias true to /*.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. I'm happy to keep things as they are.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah its what pete said - router worker actually getst this as two different config options invoke_user_worker_ahead_of_assets or static_routing

@emily-shen emily-shen force-pushed the emily/routes-plumbing-take-2 branch from a73a801 to 957e4a4 Compare June 11, 2025 13:53
@emily-shen emily-shen added this pull request to the merge queue Jun 11, 2025
@emily-shen emily-shen removed this pull request from the merge queue due to a manual request Jun 11, 2025
@emily-shen emily-shen added this pull request to the merge queue Jun 11, 2025
Merged via the queue into main with commit 0b2ba45 Jun 11, 2025
20 checks passed
@emily-shen emily-shen deleted the emily/routes-plumbing-take-2 branch June 11, 2025 15:32
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c3-e2e Run c3 e2e tests on a PR e2e Run wrangler + vite-plugin e2e tests on a PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants