Skip to content

Conversation

@hi-ogawa
Copy link
Owner

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

The idea is:

"use client"
import { unstable_allowServer as allowServer } from 'waku/client';
import { atom } from 'jotai/vanilla';
import clientDep from "./client-dep" // 🗑️

const local1 = 1;
export const countAtom = allowServer(atom(local1));

const local2 = 2; // 🗑️
export const MyClientComp = () => <div>hey: {local2} {clientDep}</div>  // 🗑️

⬇️ custom DCE (implement it in Waku)

"use client"
import { atom } from 'jotai/vanilla';

const local1 = 1;
export const countAtom = atom(local1);

export const MyClientComp = () => { throw new Error('... waku error ...') }

⬇️ rsc plugin use client transform with keep: true

"use client"
import { atom } from 'jotai/vanilla';

const local1 = 1;
export const countAtom = $$register(atom(local1), ...)  // just wrap 🎁

export const MyClientComp = $$register(() => { throw new Error('... waku error ...') }, ...) // 🎁

It doesn't feel this is a good generalization, but for now let's go with whatever works.

Copy link
Owner Author

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

@hi-ogawa hi-ogawa changed the title feat(rsc,transforms): support keeping proxy value feat(rsc,transforms): support preserving client reference original value Jun 25, 2025
@hi-ogawa hi-ogawa changed the title feat(rsc,transforms): support preserving client reference original value feat(rsc, transforms): support preserving client reference original value Jun 25, 2025
@hi-ogawa hi-ogawa force-pushed the 06-25-feat_rsc_transforms_support_keeping_proxy_value branch from b134263 to 8f73785 Compare June 25, 2025 04:16
@hi-ogawa hi-ogawa marked this pull request as ready for review June 25, 2025 06:34
@hi-ogawa hi-ogawa mentioned this pull request Jun 25, 2025
10 tasks
@hi-ogawa hi-ogawa merged commit 92ca9f8 into main Jun 25, 2025
12 checks passed
@hi-ogawa hi-ogawa deleted the 06-25-feat_rsc_transforms_support_keeping_proxy_value branch June 25, 2025 08:32
dai-shi pushed a commit to wakujs/waku that referenced this pull request Aug 3, 2025
(EDIT: see also blog post for the summary
#1564)

This PR replaces Waku's `vite` and `react-server-dom-webpack` internals
with `@vitejs/plugin-rsc`.

The new code path is split in `waku/src/vite-rsc/...` but Waku's core
routing logic is reused internally. Previously implementation is still
preserved and can be enabled via a flag `--experimental-legacy-cli` e.g.

```sh
pnpm -C examples/01_template dev --experimental-legacy-cli
```

The goal is to achieve the switch with as little breaking change as
possible. 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!

## known changes

- new `{ vite: ... }` config in `waku.config.ts`
- this replaces custom `vite.config.ts` and `unstable_viteConfigs` in
`waku.config.ts`
- custom plugin can access environment API configuration and plugin
system
    - https://vite.dev/guide/api-environment.html
    - https://vite.dev/guide/api-environment-plugins.html

```js
// waku.config.ts
import { defineConfig } from "waku/config"

export default defineConfig({
  vite: {
    plugins: [ ... ],
    environments: {
      client: { ... },
      ssr: { ... },
      rsc: { ... },
    }
  }
})
```

- `ssr` environment (previously "main server ssr") doesn't externalize
server deps by default, but transform all react deps.
- This means if there's cjs dependency (directly or transitively) used
in client component, SSR might fail during dev. For example, `swr` (esm)
package uses `use-sync-external-store` (cjs) internally. This can be
mitigated by `environments.ssr.optimizeDeps.include: ["swr"]`.
  - See also vitejs/vite-plugin-react#610

## e2e status

Run it locally e.g. by

```js
TEST_VITE_RSC=1 pnpm exec playwright test --project=chromium-dev e2e/rsc-basic.spec.ts
pnpm -C e2e/fixtures/rsc-basic dev --experimental-vite-rsc
```

- [x] broken-links
- [x] create-pages
- [x] define-router
- [x] fs-router
- [x] hot-reload
- [x] monorepo
- [x] multi-platform
- [x] partial-build
- [x] render-type
- [x] rsc-asset
- [x] rsc-basic
- [x] rsc-css-modules
- [x] ssg-performance
- [x] ssg-wildcard
- [x] ssr-basic
- [x] ssr-catch-error
- [x] ssr-context-provider
- [x] ssr-redirect
- [x] ssr-swr
- [x] ssr-target-bundle
- [x] use-router
- [x] examples-smoke
  - [x] 11_fs-router (build)
  - [x] 12_nossr (build)
  - [x] 36_form (see #1534)
  - [x] 38_cookies (build)
  - [x] website

## todo 

- [x] test: `waitForHydration` or not?
#1493 (comment)
- [x] reduce diff
- [ ] announcement #1564
- [ ] discuss dependency structure (dep vs peer-dep,
`@hiogawa/vite-plugin` or wait for it to move to vitejs org)
- [ ] replace completely hi-ogawa#20
- [x] test: fix windows ci fail
hi-ogawa#11
- [x] deployment adapter hi-ogawa#8
  - vercel example https://waku-vite-rsc-01-template.vercel.app
- [x] "use client" transform with `allowServer`
hi-ogawa/vite-plugins#1078
- [x] improve waku.config support
hi-ogawa#5
- [x] polish middleware hi-ogawa#7
- [x] integrate hono hi-ogawa#6
- [ ] check if any known issues will be fixed by this change. (if it's
still not working, check if it's also reproduce with
https://github.com/hi-ogawa/vite-plugins/tree/main/packages/rsc and
raise it as an upstream issue)
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