Skip to content

Conversation

@hi-ogawa
Copy link
Owner

@hi-ogawa hi-ogawa commented Jun 20, 2025

Note

The PR is moved to the official repo wakujs#1493

old comment

This PR replaces Waku's vite and react-server-dom-webpack internals with "Vite RSC API" provided by @hiogawa/vite-rsc package. (It's currently my own package, but the plan is to move/split it to under @vitejs/plugin-rsc and react-server-dom-vite in the future. See also hi-ogawa/vite-plugins#1037)

Currently the new code path is split in waku/vite-rsc/... but most of Waku's core routing logic is reused internally. This mode is available by running the same cli with a flag waku --experimental-vite-rsc. For example, you can try it out the default template by:

pnpm -C examples/01_template dev --experimental-vite-rsc

The package is published on pkg.pr.new from the branch, so you can try it out on your project by installing https://pkg.pr.new/hi-ogawa/waku@(commit).

The goal is to achieve the switch without breaking change. There are still missing pieces as I wrote in todo at the bottom, but the overall shape is mostly established, so I'm opening a PR here to start to gather feedback. Thanks!

e2e status

Run it locally e.g. by

TEST_VITE_RSC=1 pnpm exec playwright test --project=chromium-dev /rsc-basic
pnpm -C e2e/fixtures/rsc-basic dev --experimental-vite-rsc

✅: pass
❌: some fails
❓: flaky?
⚠️: pass but not functioning

  • broken-links ✅
  • create-pages ✅ ("long suspense" on firefox-prd❓)
  • define-router ✅
  • fs-router ✅
  • hot-reload (syntax error ❌)
  • monorepo ✅
  • multi-platform ⚠️
  • partial-build ✅
  • render-type ✅
  • rsc-asset ✅
  • rsc-basic ✅
  • rsc-css-modules ✅
  • ssg-performance ✅
  • ssg-wildcard ✅
  • ssr-basic ✅
  • ssr-catch-error ✅
  • ssr-context-provider ✅
  • ssr-redirect ✅ ("access async page directly" ❓)
  • ssr-swr ✅
  • ssr-target-bundle ✅
  • use-router ✅

todo

@hi-ogawa hi-ogawa force-pushed the chore-vite-rsc branch 2 times, most recently from a31acf3 to babc4fc Compare June 21, 2025 07:18
hi-ogawa added a commit to hi-ogawa/vite-plugins that referenced this pull request Jun 21, 2025
I think we should do this by default (but don't make it build error yet). Found while testing hi-ogawa/waku#2
@hi-ogawa hi-ogawa changed the title refactor: use vite-rsc (poc) feat: add Vite RSC API port Jun 22, 2025
@hi-ogawa hi-ogawa changed the title feat: add Vite RSC API port feat: use Vite RSC API Jun 24, 2025
@rmarscher
Copy link

rmarscher commented Jun 24, 2025

This is amazing work. Thank you.

I like how there are separate public, ssr, and rsc folders in a project built with waku/vite-rsc. I see that dist/rsc/index.js exports handler as default, so it needs a listener runtime to receive requests and invoke the handler. The cli is using vite preview for waku start.

Waku could provide some default listeners for @hono/node-server, bun, hono/aws-lambda, cloudflare workers, etc. A Waku app could import one of those handlers or supply its own - maybe using a virtual module to import the RSC handler and pass it the Request object and handle the response. By default, for prod, it could bundle @hono/node-server or use vite preview.

I like how the waku/vite-rsc demo here uses the environment API. That will make it possible to use the Cloudflare Vite plugin. I opened this discussion when the Cloudflare Vite plugin was announced with React Router support. wakujs#1388

It would be great to be able to customize the handler server entry that is used for prod and dev with the Environment API. When creating an app for Cloudflare Workers, the handler server entry could be customized to add additional handlers and durable objects.

@hi-ogawa
Copy link
Owner Author

@rmarscher Thanks for testing out! I'm talking with Daishi and I'll soon move this PR to Waku repo for review and discussions.

As to Cloudflare features, this change should make it easier to integrate their vite plugin both on dev and build. Not with Waku, but I have two examples here to use @cloudflare/vite-plugin with rsc plugin if you are interested. https://github.com/hi-ogawa/vite-plugins/blob/main/packages/rsc/examples/react-router/cf/vite.config.ts, https://github.com/hi-ogawa/vite-plugins/blob/main/packages/rsc/examples/starter-cf-single/vite.config.ts. At the moment, making Waku work with cloudflare vite plugin is not the immediate goal, but please feel free to explore if you like and I'm happy to help 🙂

Copy link
Owner Author

hi-ogawa commented Jun 27, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

This was referenced Jun 27, 2025
@hi-ogawa hi-ogawa mentioned this pull request Jun 27, 2025
hi-ogawa and others added 28 commits July 31, 2025 11:57
Co-authored-by: Hiroshi Ogawa <[email protected]>
Co-authored-by: Daishi Kato <[email protected]>
changelog:
https://devblogs.microsoft.com/typescript/announcing-typescript-5-9/

I guess import defer could be an awesome feature we might use that
(maybe)?

Co-authored-by: Daishi Kato <[email protected]>
This adds a test case for fallback index.html as discussed in
wakujs#1493 (comment)
@hi-ogawa hi-ogawa closed this Aug 5, 2025
@hi-ogawa hi-ogawa deleted the chore-vite-rsc branch August 5, 2025 08: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.

8 participants