-
Notifications
You must be signed in to change notification settings - Fork 702
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
fix(wrangler): Fix pages dev
watch mode [_worker.js]
#6150
Conversation
🦋 Changeset detectedLatest commit: de6fbc2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9796131036/npm-package-wrangler-6150 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6150/npm-package-wrangler-6150 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9796131036/npm-package-wrangler-6150 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9796131036/npm-package-create-cloudflare-6150 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9796131036/npm-package-cloudflare-kv-asset-handler-6150 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9796131036/npm-package-miniflare-6150 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9796131036/npm-package-cloudflare-pages-shared-6150 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9796131036/npm-package-cloudflare-vitest-pool-workers-6150 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just some minor comments, but nothing blocking.
00aef57
to
4cb8715
Compare
4cb8715
to
d4e1c8c
Compare
d4e1c8c
to
536836f
Compare
Approved pending #6150 (comment), which I'm likely misunderstanding |
d360b9f
to
e3b1f9b
Compare
The watch mode in `pages dev` for Advanced Mode projects is currently partially broken, as it only watches for changes in the `_worker.js` file, but not for changes in any of its imported dependencies. This means that given the following `_worker.js` file ``` import { graham } from "./graham-the-dog"; export default { fetch(request, env) { return new Response(graham) } } ``` `pages dev` will reload for any changes in the `_worker.js` file itself, but not for any changes in `graham-the-dog.js`, which is its dependency. Similarly, `pages dev` will not reload for any changes in non-JS module imports, such as wasm/html/binary module imports. This commit addresses all the aforementioned issues. Fixes #4824
e3b1f9b
to
de6fbc2
Compare
What this PR solves / how to test
The watch mode in
pages dev
for Advanced Mode projects is currently partially broken, as it only watches for changes in the_worker.js
file, but not for changes in any of its imported dependencies. This means that given the following_worker.js
filepages dev
will reload for any changes in the_worker.js
file itself, but not for any changes ingraham-the-dog.js
, which is its dependency.Similarly,
pages dev
will not reload for any changes in non-JS module imports, such as wasm/html/binary module imports.This commit addresses all the aforementioned issues.
Fixes #4824
Solutions we considered
Our original solution was implemented using esbuild's
watch
mode (see dd6cd19), which basically meant just enabling thewatch
flag inbuildRawWorker()
. Turned out though (via failed test in CI), that this solution introduced a regression for a frameworks corner case...the deletion of_worker.js
itself (please see #4877 and #3886).When used in the context of frameworks, the assets directory served by
pages dev
gets rebuilt (removed + added back with updated assets) by a separate process, external to wrangler (I'm no expert here on the exact details, but I assume this more or less to be the case). This affects key Pages files, such as_worker.js
and_routes.json
, which get deleted/added back as part of that assets directory, which in turn, triggers a_worker.js
rebuild. If the_worker.js
re-build is triggered before the external process gets a chance to add the file back,pages dev
will show a bunch of errors in the terminal, which, while accurate, seem to be confusing/annoying for our users. This was fixed by #4877 by completely turning off Worker rebuilds for chokidar "unlink` events.Unfortunately, the behaviour for this particular use case is very hard to port to esbuild watch mode, since esbuild gives us very limited information wrt to what changed ....so here we are 😢
This lead us to the second implementation (see 5c8fcf0), which, similar to Functions, delegates the entirety of the watch mechanism to
chokidar
.How we tested the changes
This PR comes with e2e tests, but in addition to them, we've manually tested these changes in the following scenarios:
_worker.js
_worker.js
Author has addressed the following