Skip to content

Commit 45e55fb

Browse files
committed
Some more fixes
1 parent f72091c commit 45e55fb

File tree

5 files changed

+67
-13
lines changed

5 files changed

+67
-13
lines changed

code/frameworks/nextjs-vite-rsc/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type vitePluginStorybookNextJs from 'vite-plugin-storybook-nextjs';
1010
import * as nextPreview from './preview';
1111
import type { NextJsTypes } from './types';
1212

13-
export * from '@storybook/react';
13+
// export * from '@storybook/react';
1414
export * from './types';
1515

1616
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

code/frameworks/nextjs-vite-rsc/src/preview.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { type RenderContext } from 'storybook/internal/types';
55

66
import type { Decorator, Preview, ReactRenderer } from '@storybook/react';
77

8-
import { NextRouter } from '@storybook/nextjs-vite-rsc/rsc/client';
9-
8+
// import { NextRouter } from '@storybook/nextjs-vite-rsc/rsc/client';
109
import { isNextRouterError } from 'next/dist/client/components/is-next-router-error';
1110
import { defaultDecorateStory } from 'storybook/preview-api';
1211

@@ -54,11 +53,11 @@ globalThis.addEventListener('error', (ev: WindowEventMap['error']): void => {
5453
});
5554

5655
export const decorators: Decorator[] = [
57-
(Story, context) => (
58-
<NextRouter>
59-
<Story />
60-
</NextRouter>
61-
),
56+
// (Story, context) => (
57+
// <NextRouter>
58+
// <Story />
59+
// </NextRouter>
60+
// ),
6261
// TODO
6362
// StyledJsxDecorator,
6463
// ImageDecorator,

code/frameworks/nextjs-vite-rsc/src/rsc-plugin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export function rscBrowserModePlugin(): Plugin[] {
2020
define: {
2121
'import.meta.env.__vite_rsc_build__': JSON.stringify(env.command === 'build'),
2222
},
23+
optimizeDeps: {
24+
exclude: [
25+
'virtual:vite-rsc-browser-mode/build-server-references',
26+
'virtual:vite-rsc-browser-mode/load-client',
27+
],
28+
},
2329
environments: {
2430
client: {
2531
keepProcessEnv: false,
@@ -57,6 +63,7 @@ export function rscBrowserModePlugin(): Plugin[] {
5763
'react/jsx-runtime',
5864
'react/jsx-dev-runtime',
5965
'@vitejs/plugin-rsc/vendor/react-server-dom/client.browser',
66+
'@storybook/nextjs-vite-rsc/navigation',
6067
],
6168
exclude: ['@vitejs/plugin-rsc'],
6269
esbuildOptions: {
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies';
22
import { HeadersAdapter } from 'next/dist/server/web/spec-extension/adapters/headers';
3-
import { RequestCookiesAdapter } from 'next/dist/server/web/spec-extension/adapters/request-cookies';
3+
import { fn } from 'storybook/test';
44

5-
const headersAdapter = new HeadersAdapter({});
6-
export const headers = () => headersAdapter;
7-
export const cookies = () => RequestCookiesAdapter.seal(new RequestCookies(headersAdapter));
5+
let headersAdapter = new HeadersAdapter({});
6+
let requestCookies = new RequestCookies(headersAdapter);
7+
8+
export const cookies = fn(() => requestCookies);
9+
export const headers = fn(() => headersAdapter);
10+
11+
const originalRestore = cookies.mockRestore.bind(null);
12+
13+
cookies.mockRestore = () => {
14+
originalRestore();
15+
headersAdapter = new HeadersAdapter({});
16+
requestCookies = new RequestCookies(headersAdapter);
17+
};
Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1-
export * from 'next/navigation';
1+
'use client';
2+
3+
import {
4+
ReadonlyURLSearchParams,
5+
RedirectType,
6+
ServerInsertedHTMLContext,
7+
forbidden,
8+
notFound,
9+
permanentRedirect,
10+
redirect,
11+
unauthorized,
12+
unstable_rethrow,
13+
useParams,
14+
usePathname,
15+
useRouter,
16+
useSearchParams,
17+
useSelectedLayoutSegment,
18+
useSelectedLayoutSegments,
19+
useServerInsertedHTML,
20+
} from 'next/dist/client/components/navigation';
21+
22+
export {
23+
useParams,
24+
usePathname,
25+
useRouter,
26+
useSearchParams,
27+
useSelectedLayoutSegment,
28+
useSelectedLayoutSegments,
29+
useServerInsertedHTML,
30+
notFound,
31+
forbidden,
32+
permanentRedirect,
33+
ReadonlyURLSearchParams,
34+
redirect,
35+
ServerInsertedHTMLContext,
36+
unauthorized,
37+
unstable_rethrow,
38+
RedirectType,
39+
};

0 commit comments

Comments
 (0)