Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/plugin-rsc/examples/browser-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
"license": "MIT",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "rm -rf ./node_modules/.vite && vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@storybook/nextjs-vite-rsc": "0.0.0-pr-32412-sha-b8362176",
"storybook": "0.0.0-pr-32412-sha-b8362176",
"react": "^19.1.1",
"react-dom": "^19.1.1"
"react-dom": "^19.1.1",
"next": "^15.5.4"
},
"devDependencies": {
"@types/react": "^19.1.16",
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-rsc/examples/browser-mode/src/client.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
'use client'

import React from 'react'
import { usePathname } from 'next/navigation'

export function ClientCounter() {
const pathname = usePathname()
const [count, setCount] = React.useState(0)

return (
<button onClick={() => setCount((count) => count + 1)}>
Client Counter: {count}
Client Counter: {count} <br />
Injected pathname: {pathname}
</button>
)
}
20 changes: 19 additions & 1 deletion packages/plugin-rsc/examples/browser-mode/src/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,26 @@ import { ClientCounter } from './client.tsx'
import { TestUseActionState } from './action-from-client/client.tsx'
import { TestActionBind } from './action-bind/server.tsx'

// Using a server component that uses NextRouter does not work
import { ServerComponent } from '@storybook/nextjs-vite-rsc/repro'

// using the client component directly works
import { NextRouter } from '@storybook/nextjs-vite-rsc/rsc/client'

export function Root() {
return <App />
return (
<ServerComponent>
<App />
</ServerComponent>
)
}

export function WorkingRoot() {
return (
<NextRouter url="/some-path-name">
<App />
</NextRouter>
)
}

function App() {
Expand Down
18 changes: 18 additions & 0 deletions packages/plugin-rsc/examples/browser-mode/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getPluginApi,
type PluginApi,
} from '@vitejs/plugin-rsc/plugin'
import * as path from 'node:path'
// import inspect from 'vite-plugin-inspect'

export default defineConfig({
Expand Down Expand Up @@ -35,10 +36,24 @@ function rscBrowserModePlugin(): Plugin[] {
config(userConfig, env) {
return {
define: {
'process.env': JSON.stringify({}),
__dirname: JSON.stringify(null),
'import.meta.env.__vite_rsc_build__': JSON.stringify(
env.command === 'build',
),
},
resolve: {
alias: {
'@vercel/turbopack-ecmascript-runtime/browser/dev/hmr-client/hmr-client.ts':
'next/dist/client/dev/noop-turbopack-hmr',
'react-server-dom-webpack/client': path.resolve(
'../../dist/vendor/react-server-dom/client.edge.js',
),
'react-server-dom-webpack/client.edge': path.resolve(
'../../dist/vendor/react-server-dom/client.edge.js',
),
},
},
environments: {
client: {
keepProcessEnv: false,
Expand All @@ -54,6 +69,7 @@ function rscBrowserModePlugin(): Plugin[] {
'react/jsx-dev-runtime',
'@vitejs/plugin-rsc/vendor/react-server-dom/server.edge',
'@vitejs/plugin-rsc/vendor/react-server-dom/client.edge',
'@storybook/nextjs-vite-rsc/rsc/client',
],
exclude: ['vite', '@vitejs/plugin-rsc'],
},
Expand All @@ -75,6 +91,8 @@ function rscBrowserModePlugin(): Plugin[] {
'react/jsx-runtime',
'react/jsx-dev-runtime',
'@vitejs/plugin-rsc/vendor/react-server-dom/client.browser',
'@storybook/nextjs-vite-rsc/rsc/client',
'next/navigation',
],
exclude: ['@vitejs/plugin-rsc'],
esbuildOptions: {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export function vitePluginRscMinimal(
...vitePluginUseServer(rscPluginOptions, manager),
...vitePluginDefineEncryptionKey(rscPluginOptions),
scanBuildStripPlugin({ manager }),
...cjsModuleRunnerPlugin(),
]
}

Expand Down
Loading
Loading