-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Nextjs: New rsc vite framework #32412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: kasper/nextjs-vite-rsc-base-2
Are you sure you want to change the base?
Changes from all commits
a6cf9bf
b7341cb
c9bbef9
b36accd
5972849
06b9fc9
301b498
d4baeb3
f670336
4e0feb2
f72091c
45e55fb
addd771
28e4f03
efd206f
076721d
826e97d
4488c15
b836217
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { ESModulesEvaluator, ModuleRunner } from 'vite/module-runner'; | ||
|
|
||
| export default async function loadClient() { | ||
| const runner = new ModuleRunner( | ||
| { | ||
| sourcemapInterceptor: false, | ||
| transport: { | ||
| invoke: async (payload) => { | ||
| const response = await fetch( | ||
| '/@vite/invoke-react-client?' + | ||
| new URLSearchParams({ | ||
| data: JSON.stringify(payload), | ||
| }) | ||
| ); | ||
| return response.json(); | ||
| }, | ||
| }, | ||
| hmr: false, | ||
| }, | ||
| new ESModulesEvaluator() | ||
| ); | ||
| return await runner.import<typeof import('@storybook/nextjs-vite-rsc/react-client')>( | ||
| '@storybook/nextjs-vite-rsc/react-client' | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| // https://storybook.js.org/docs/react/addons/writing-presets | ||
| import { createRequire } from 'node:module'; | ||
| import { dirname } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
|
|
@@ -12,12 +10,7 @@ import { viteFinal as reactViteFinal } from '@storybook/react-vite/preset'; | |
|
|
||
| import postCssLoadConfig from 'postcss-load-config'; | ||
|
|
||
| import type { FrameworkOptions } from './types'; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
|
|
||
| // the ESM output of this package is broken, so I had to force it to use the CJS version it's shipping. | ||
| const vitePluginStorybookNextjs = require('vite-plugin-storybook-nextjs'); | ||
| import { rscBrowserModePlugin, vitestPluginNext } from './rsc-plugin'; | ||
|
|
||
| export const core: PresetProperty<'core'> = async (config, options) => { | ||
| const framework = await options.presets.apply('framework'); | ||
|
|
@@ -30,20 +23,24 @@ export const core: PresetProperty<'core'> = async (config, options) => { | |
| ...(typeof framework === 'string' ? {} : framework.options.builder || {}), | ||
| }, | ||
| }, | ||
| renderer: fileURLToPath(import.meta.resolve('@storybook/react/preset')), | ||
| renderer: undefined, | ||
| }; | ||
| }; | ||
|
|
||
| export const previewAnnotations: PresetProperty<'previewAnnotations'> = (entry = []) => { | ||
| const result = [...entry, fileURLToPath(import.meta.resolve('@storybook/nextjs-vite/preview'))]; | ||
| const result = [ | ||
| ...entry, | ||
| fileURLToPath(import.meta.resolve('@storybook/nextjs-vite-rsc/preview')), | ||
| ]; | ||
| return result; | ||
| }; | ||
|
|
||
| export const optimizeViteDeps = [ | ||
| '@storybook/nextjs-vite/navigation.mock', | ||
| '@storybook/nextjs-vite/router.mock', | ||
| '@storybook/nextjs-vite > styled-jsx', | ||
| '@storybook/nextjs-vite > styled-jsx/style', | ||
| 'next/dist/client/components/is-next-router-error', | ||
| '@storybook/nextjs-vite-rsc/navigation.mock', | ||
| '@storybook/nextjs-vite-rsc/router.mock', | ||
| '@storybook/nextjs-vite-rsc > styled-jsx', | ||
| '@storybook/nextjs-vite-rsc > styled-jsx/style', | ||
| ]; | ||
|
Comment on lines
38
to
44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainDouble‑check optimizeDeps include syntax for transitive deps. Entries like Run: 🏁 Script executed: #!/bin/bash
# See how other frameworks structure this and whether '>' is used project-wide
rg -n -C2 'optimizeViteDeps|optimizeDeps' code/ | sed -n '1,200p'
rg -nP '>\s*styled-jsx' code/Length of output: 7058 Replace unconventional
🤖 Prompt for AI Agents |
||
|
|
||
| export const viteFinal: StorybookConfigVite['viteFinal'] = async (config, options) => { | ||
|
|
@@ -62,10 +59,6 @@ export const viteFinal: StorybookConfigVite['viteFinal'] = async (config, option | |
| } | ||
| } | ||
|
|
||
| const { nextConfigPath } = await options.presets.apply<FrameworkOptions>('frameworkOptions'); | ||
|
|
||
| const nextDir = nextConfigPath ? dirname(nextConfigPath) : undefined; | ||
|
|
||
| return { | ||
| ...reactConfig, | ||
| resolve: { | ||
|
|
@@ -77,6 +70,6 @@ export const viteFinal: StorybookConfigVite['viteFinal'] = async (config, option | |
| 'styled-jsx/style.js': fileURLToPath(import.meta.resolve('styled-jsx/style')), | ||
| }, | ||
| }, | ||
| plugins: [...(reactConfig?.plugins ?? []), vitePluginStorybookNextjs({ dir: nextDir })], | ||
| plugins: [...(reactConfig?.plugins ?? []), rscBrowserModePlugin(), vitestPluginNext()], | ||
| }; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type safety regression: prefer precise typings over
any.The function signature changed from
PlayFunction<TRenderer>to(...args: any[]) => any, eliminating type safety. This violates the coding guideline to "prefer precise typings instead of using any or suppressions, consistent with strict mode."If framework flexibility is required, consider alternatives that preserve type safety:
As per coding guidelines.
🤖 Prompt for AI Agents