Skip to content

Conversation

@pi0
Copy link
Member

@pi0 pi0 commented Jan 21, 2026

We use static flags from a virtual import + optimization.inlineConst + minify: dce-only to enable rolldown / rolldown-vite to tree-shake unused logic.

However it seems not effective on entrypoints where we conditionally import crossws for opt-in websocket feature (/cc @sapphi-red it is reprodicable with both rolldown and vite8 with any nitro nightly before this)

This PR worksaround issue by using a replacement via import.meta..

@vercel
Copy link

vercel bot commented Jan 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
nitro.build Ready Ready Preview, Comment Jan 21, 2026 6:24pm

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Jan 21, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Refactors WebSocket feature detection from compile-time feature flags to runtime metadata injection. Removes the hasWebSocket generated flag constant and replaces all occurrences with import.meta._websocket, injected via build config and exposed through the NitroImportMeta interface.

Changes

Cohort / File(s) Summary
Build configuration and types
src/build/config.ts, src/types/global.ts
Adds _websocket property to importMetaInjections with fallback logic (features.websocket ?? experimental.websocket); extends NitroImportMeta interface with optional _websocket?: boolean property.
Virtual feature-flags generation
src/build/virtual/feature-flags.ts, src/runtime/virtual/feature-flags.ts
Removes hasWebSocket constant generation and export from both build-time and runtime feature-flags modules.
Build dev tooling
src/build/vite/dev.ts
Inlines WebSocket feature check; replaces hasWebSocket variable with direct evaluation of nitro.options.features.websocket ?? nitro.options.experimental.websocket.
Runtime preset implementations
src/presets/_nitro/runtime/nitro-dev.ts, src/presets/bun/runtime/bun.ts, src/presets/cloudflare/runtime/{cloudflare-durable,cloudflare-module,cloudflare-pages}.ts, src/presets/deno/runtime/{deno-deploy,deno-server}.ts, src/presets/node/runtime/{node-cluster,node-middleware,node-server}.ts, src/runtime/internal/vite/dev-entry.mjs
Replaces hasWebSocket imports and checks with import.meta._websocket for conditional WebSocket adapter initialization and upgrade handler registration across all preset runtimes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/ws-shake

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pi0 pi0 changed the title fix: use static flag for websocket feature fix: use static replacement for websocket feature Jan 21, 2026
@pi0 pi0 merged commit b2b3788 into main Jan 21, 2026
8 of 9 checks passed
@pi0 pi0 deleted the fix/ws-shake branch January 21, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants