Skip to content

Use hook filters#12214

Merged
jamesopstad merged 7 commits intomainfrom
james/hook-filters
Jan 30, 2026
Merged

Use hook filters#12214
jamesopstad merged 7 commits intomainfrom
james/hook-filters

Conversation

@jamesopstad
Copy link
Copy Markdown
Contributor

@jamesopstad jamesopstad commented Jan 28, 2026

Use Hook Filters to optimize plugin performance with Vite 8. This skips unnecessary Rust-to-JS calls with Rolldown powered Vite.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal change

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 28, 2026

🦋 Changeset detected

Latest commit: 9af37dc

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

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

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jan 28, 2026

Claude finished @jamesopstad's task —— View job


Changeset Review

✅ All changesets look good

The changeset at .changeset/tough-views-make.md is well-formatted:

  • Version type: minor is appropriate for a performance optimization feature
  • Description: Clear and includes a link to the Hook Filters documentation
  • No markdown headers: ✓ (no h1/h2/h3 headers present)
  • Package: @cloudflare/vite-plugin is correctly specified

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 28, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 9af37dc

@jamesopstad jamesopstad force-pushed the james/hook-filters branch 2 times, most recently from 74deed5 to 0704c22 Compare January 28, 2026 20:02
@jamesopstad jamesopstad marked this pull request as ready for review January 28, 2026 20:08
@jamesopstad jamesopstad requested a review from a team as a code owner January 28, 2026 20:08
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional flags.

Open in Devin Review

Copy link
Copy Markdown
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.

A few non-blocking questions.

if (id === `\0${VIRTUAL_WORKER_ENTRY}`) {
const nodeJsCompat = ctx.getNodeJsCompat(this.environment.name);
load: {
filter: { id: virtualCloudflareLoadRE },
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.

Are there other virtual modules that could trigger this filter but are not handled by the loader?

Could we lock down this filter even more so that it only triggers if the three handled virtual entry-points are loaded?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it's OK as the we are reserving the virtual:cloudflare/ prefix for virtual modules handled by this plugin.

Comment thread packages/vite-plugin-cloudflare/src/plugins/virtual-modules.ts Outdated
id: [nodeBuiltinsRE, /^unenv\//, /^@cloudflare\/unenv-preset\//],
},
async handler(source, importer, options) {
const nodeJsCompat = ctx.getNodeJsCompat(this.environment.name);
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.

No fallback filtering here?

Copy link
Copy Markdown
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 it's needed here because it already returns early if there is no result:

// See if we can map the `source` to a Node.js compat alias.
const result = nodeJsCompat.resolveNodeJsImport(source);
if (!result) {
return;
}

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jan 30, 2026
@jamesopstad jamesopstad merged commit 4db3864 into main Jan 30, 2026
37 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jan 30, 2026
@jamesopstad jamesopstad deleted the james/hook-filters branch January 30, 2026 12:52
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.

3 participants