Skip to content

feat(vite-plugin-cloudflare): surface binding info#11045

Merged
edmundhung merged 5 commits intomainfrom
edmundhung/vite-surface-bindings-info
Dec 12, 2025
Merged

feat(vite-plugin-cloudflare): surface binding info#11045
edmundhung merged 5 commits intomainfrom
edmundhung/vite-surface-bindings-info

Conversation

@edmundhung
Copy link
Member

@edmundhung edmundhung commented Oct 21, 2025

Fixes DEVX-2116

This PR adds keyboard shortcut (b + enter) to display worker bindings during development and it works with both dev and preview server.

Screenshot 2025-10-23 at 15 51 17
  • Tests
    • Tests included
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: vite integration
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: not wrangler feature

@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2025

🦋 Changeset detected

Latest commit: e09c669

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 21, 2025

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 5f2d4ba

@edmundhung edmundhung force-pushed the edmundhung/vite-surface-bindings-info branch 6 times, most recently from 67d69b5 to f99b468 Compare October 23, 2025 13:43
@edmundhung edmundhung marked this pull request as ready for review October 23, 2025 14:46
@edmundhung edmundhung requested a review from a team as a code owner October 23, 2025 14:46
@edmundhung edmundhung requested a review from a team October 23, 2025 14:46
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.

This is looking good. I've added some minor changes but the main thing I've noticed is that the bindings don't update when the config file is updated. It will need to be updated so that the shortcut always display the latest bindings.

process.stdout.columns;

logger.log(title);
log(title);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a blank line after the title?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's updates the format of the bindings table in a seperate PR as it will impact a huge amounts of snapshots test.

}
if (tailConsumers !== undefined && tailConsumers.length > 0) {
logger.log(
log(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need a blank line after tail consumers or multiple Workers end up in the same paragraph.

@github-project-automation github-project-automation bot moved this from Untriaged to In Review in workers-sdk Oct 24, 2025
@edmundhung edmundhung force-pushed the edmundhung/vite-surface-bindings-info branch from 7e5e016 to d8791d1 Compare October 27, 2025 11:02
@petebacondarwin petebacondarwin marked this pull request as draft November 13, 2025 15:14
@edmundhung edmundhung force-pushed the edmundhung/vite-surface-bindings-info branch from d8791d1 to 22effc1 Compare November 14, 2025 18:06
@edmundhung edmundhung force-pushed the edmundhung/vite-surface-bindings-info branch 3 times, most recently from cafac13 to 1652a30 Compare December 2, 2025 15:29
@edmundhung edmundhung force-pushed the edmundhung/vite-surface-bindings-info branch 5 times, most recently from d28c425 to a604f65 Compare December 10, 2025 15:43
@edmundhung edmundhung marked this pull request as ready for review December 10, 2025 16:26
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.

Left some comments that need addressing but generally looks good.

const require = createRequire(import.meta.url);

export function satisfiesViteVersion(minVersion: string): boolean {
const viteVersion = require("vite/package.json").version as string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const viteVersion = require("vite/package.json").version as string;
const viteVersion = require("vite/package.json").version as string;

This can be replaced with importing version from vite.

Copy link
Member Author

Choose a reason for hiding this comment

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

The suggestions shown in your comment looks identical 😅 Do you mean import { version } from "vite"?

I tried that and it returns me the version we used for development instead of user's vite version.

Copy link
Contributor

Choose a reason for hiding this comment

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

The suggestions shown in your comment looks identical 😅 Do you mean import { version } from "vite"?

Haha, sorry, I didn't mean to add a suggestion

I tried that and it returns me the version we used for development instead of user's vite version.

I'm pretty sure this will only be the case if you're running in the monorepo and haven't updated the Vite version globally. Linked dependencies get resolved differently. Please build the Vite plugin and then run pnpm update -r --no-save vite@7.2.7 before testing to verify.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I understand it's a monorepo issue as the pre-release works. I just wasn't sure how to test that in our repo (instead of manually testing it)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it's a little annoying but there's no way to reliably run the playground tests with a different version of Vite to the plugin package so both need to be updated. Otherwise the tests actually run with two versions of Vite, which can lead to some strange behaviour.

if (hasConnectionStatus && !isConnectedStatusExplained) {
log(
dim(
`\nService bindings, Durable Object bindings, and Tail consumers connect to other Wrangler or Vite dev processes running locally, with their connection status indicated by ${chalk.green("[connected]")} or ${chalk.red("[not connected]")}. For more details, refer to https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#local-development\n`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`\nService bindings, Durable Object bindings, and Tail consumers connect to other Wrangler or Vite dev processes running locally, with their connection status indicated by ${chalk.green("[connected]")} or ${chalk.red("[not connected]")}. For more details, refer to https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#local-development\n`
`\nService bindings, Durable Object bindings, and Tail consumers connect to other Wrangler or Vite processes running locally, with their connection status indicated by ${chalk.green("[connected]")} or ${chalk.red("[not connected]")}. For more details, refer to https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#local-development\n`

Removing dev as it could also be preview.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will update it in the follow up PR with all other message changes (as they impact a huge amount of snapshot tests in wrangler).

env.NAME_4 (CLASS_4, defined in SCRIPT_B) Durable Object local [not connected]


Service bindings, Durable Object bindings, and Tail consumers connect to other Wrangler or Vite dev processes running locally, with their connection status indicated by [connected] or [not connected]. For more details, refer to https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#local-development
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Service bindings, Durable Object bindings, and Tail consumers connect to other Wrangler or Vite dev processes running locally, with their connection status indicated by [connected] or [not connected]. For more details, refer to https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#local-development
Service bindings, Durable Object bindings, and Tail consumers connect to other Wrangler or Vite processes running locally, with their connection status indicated by [connected] or [not connected]. For more details, refer to https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#local-development

Copy link
Member Author

Choose a reason for hiding this comment

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

I will update it in the follow up PR with all other message changes (as they impact a huge amount of snapshot tests in wrangler).

@MattieTK
Copy link
Member

Nice! @emily-shen @NuroDev this might be worth looking at for what we work on in Q1 for the Vite presentation.

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.

Great! Please could you rebase on main before merging so that the tests run against Vite 8 beta. Thanks.

@github-project-automation github-project-automation bot moved this from In Review to Approved in workers-sdk Dec 12, 2025
@edmundhung edmundhung force-pushed the edmundhung/vite-surface-bindings-info branch from 963254d to c311057 Compare December 12, 2025 17:12
@edmundhung edmundhung merged commit 12a63ef into main Dec 12, 2025
38 of 39 checks passed
@edmundhung edmundhung deleted the edmundhung/vite-surface-bindings-info branch December 12, 2025 21:58
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants