-
Notifications
You must be signed in to change notification settings - Fork 1k
Vite-plugin: Add playground tests for run_worker_first support in vite preview mode
#9044
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
Vite-plugin: Add playground tests for run_worker_first support in vite preview mode
#9044
Conversation
|
|
Hey thanks for submitting this change @0xbad0c0d3. Unfortunately I think it is a bit more involved to make this work fully. I have a draft Worker that solves this problem more fully - #8494 - but due to the complexity it adds to the implementation, we want land it behind a flag. I hope to have that ready (at least the run_worker_first bits) by the end of this week. |
|
@petebacondarwin sorry. I didn't get your words:
Isn't it must be so? How other way the worker will know about request? If vite-server is the entry-point of the request... |
|
The Vite dev server is basically like an express server that has middleware. The Worker gets triggered by a middleware at the very end of the chain after all the other middlewares have had a chance to deal with the request. We have turned off most of the built in middleware so that we can handle HTML requests. But there is still middleware that will identify requests that match assets (either static or generated client side code) and will just respond with that content instead of passing it through to the other middlewares, such as the one that triggers the Worker. |
|
Actually, I was just going through my bigger PR and I realised that just adding this to miniflare options is enough to get it working in |
petebacondarwin
left a comment
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.
I don't think we can solve the vite dev mode issue so simply. I propose we change this PR to only add support for vite preview, which is quite straightforward, and then we can look into vite dev separately.
79e6192 to
bce43f0
Compare
yes, you are right, I've just got what exactly are you talking about! Rolled back the changes I've made. Will also think about it. |
|
Pushing a commit now... |
bce43f0 to
11e434c
Compare
|
This tweaks the way we update the miniflare config to be a bit simpler, and adds back in the fixture but only tests it in |
|
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/14664755364/npm-package-wrangler-9044Prereleases for other packages:
wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-cloudflare-workers-bindings-extension-9044 -O ./cloudflare-workers-bindings-extension.0.0.0-v148009b5d.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v148009b5d.vsix
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-create-cloudflare-9044 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-cloudflare-kv-asset-handler-9044
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-miniflare-9044
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-cloudflare-pages-shared-9044
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-cloudflare-unenv-preset-9044
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-cloudflare-vite-plugin-9044
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-cloudflare-vitest-pool-workers-9044
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-cloudflare-workers-editor-shared-9044
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-cloudflare-workers-shared-9044
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14664755364/npm-package-cloudflare-workflows-shared-9044Note that these links will no longer work once the GitHub Actions artifact expires. |
packages/vite-plugin-cloudflare/src/__tests__/get-miniflare-options.spec.ts
Outdated
Show resolved
Hide resolved
This update introduces support for the `run_worker_first` flag when configuring Miniflare options. A new test suite ensures proper handling of this flag, including scenarios where it is undefined. Additionally, the `miniflare-options` logic was updated to pass the flag to the worker configuration when specified.
e91bf39 to
4a88738
Compare
run_worker_first flag in Miniflare optionsrun_worker_first flag in vite preview mode
run_worker_first flag in vite preview moderun_worker_first support in vite preview mode
The concern was addressed. This PR is now only adding tests.
|
Congratulations @0xbad0c0d3, the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cm9wuj1me50410cjm5ebakxm9 This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. |
This update introduces a playground that exercises support for the
run_worker_firstflag when runningvite preview.Currently in
vite devstatic (non-HTML) assets are still handled by Vite before getting to the Worker, so there are failing use cases there.