Skip to content
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

NextJS: Support next/navigation in Next.js v13 #20065

Merged
merged 22 commits into from
Dec 7, 2022
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
46e702d
Document next/link component and create stories
valentinpalkovic Dec 1, 2022
d4d0e81
Document next/link component and create stories
valentinpalkovic Dec 1, 2022
240776b
Support next/navigation in Next.js v13
valentinpalkovic Dec 2, 2022
417dd1c
Update code/frameworks/nextjs/README.md
valentinpalkovic Dec 2, 2022
1ed89f7
Update code/frameworks/nextjs/README.md
valentinpalkovic Dec 2, 2022
51c4e83
Update code/frameworks/nextjs/README.md
valentinpalkovic Dec 2, 2022
15bb8f2
Document next/dynamic
valentinpalkovic Dec 2, 2022
66f9945
Update code/frameworks/nextjs/README.md
valentinpalkovic Dec 3, 2022
79c00af
Add E2E tests
valentinpalkovic Dec 6, 2022
95d9057
Merge branch 'valentin/document-next-link-component' into valentin/su…
valentinpalkovic Dec 6, 2022
6ad0975
Update code/e2e-tests/framework-nextjs.spec.ts
valentinpalkovic Dec 6, 2022
db814f2
Adjust newNextLinkBehavior to consider latest Next.js v13.0.6 release
valentinpalkovic Dec 6, 2022
6613e77
Adjust newNextLinkBehavior to consider latest Next.js v13.0.6 release
valentinpalkovic Dec 6, 2022
ab9e803
Update code/frameworks/nextjs/README.md
valentinpalkovic Dec 6, 2022
912ac0b
Update code/frameworks/nextjs/src/config/webpack.ts
valentinpalkovic Dec 6, 2022
1dbaac5
Rework nextjs parameters
valentinpalkovic Dec 6, 2022
a376841
Edit Readme
valentinpalkovic Dec 6, 2022
9a54fc0
Update code/frameworks/nextjs/README.md
valentinpalkovic Dec 6, 2022
c8bb3af
Merge remote-tracking branch 'origin/next' into valentin/support-next…
valentinpalkovic Dec 6, 2022
56e0fd4
Edit Readme
valentinpalkovic Dec 7, 2022
ab6a3ff
Merge remote-tracking branch 'origin/next' into valentin/support-next…
valentinpalkovic Dec 7, 2022
e456d04
Edit Readme
valentinpalkovic Dec 7, 2022
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
70 changes: 50 additions & 20 deletions code/frameworks/nextjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,55 @@ The parameter `nextjs.appDirectory` defaults to `false` if not set.

Please consider, that parameters are not deep merged. If you set `nextjs.appDirectory` to `true` in the [preview.js](https://storybook.js.org/docs/react/configure/overview#configure-story-rendering) file, you need to set it as well in your story, as soon as you want to set other options on the nextjs parameter.

#### Overriding defaults

Per-story overrides can be done by adding a `nextjs.navigation` property onto the story [parameters](https://storybook.js.org/docs/react/writing-stories/parameters). The framework will shallowly merge whatever you put here into the router.
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved

```js
// SomeComponentThatUsesTheNavigation.stories.js
import SomeComponentThatUsesTheNavigation from './SomeComponentThatUsesTheNavigation';

export default {
component: SomeComponentThatUsesTheNavigation,
};

// if you have the actions addon
// you can click the links and see the route change events there
export const Example = {
parameters: {
nextjs: {
appDirectory: true,
navigation: {
pathname: '/some-default-path',
query: {
foo: 'bar',
},
},
},
},
};
```

#### Global Defaults

Global defaults can be set in [preview.js](https://storybook.js.org/docs/react/configure/overview#configure-story-rendering) and will be shallowly merged with the default router.

```js
// .storybook/preview.js

export const parameters = {
nextjs: {
appDirectory: true,
navigation: {
pathname: '/some-default-path',
query: {
foo: 'bar',
},
},
},
};
```

#### Default Navigation Context

The default values on the stubbed navigation context are as follows:
Expand Down Expand Up @@ -246,26 +295,6 @@ const defaultNavigationContext = {
};
```

#### Global Defaults

Global defaults can be set in [preview.js](https://storybook.js.org/docs/react/configure/overview#configure-story-rendering) and will be shallowly merged with the default navigation context.

```js
// .storybook/preview.js

export const parameters = {
nextjs: {
appDirectory: true,
navigation: {
pathname: '/some-default-path',
query: {
foo: 'bar',
},
},
},
};
```

#### Actions Integration Caveats

If you override a function, you lose the automatic action tab integration and have to build it out yourself.
Expand Down Expand Up @@ -401,6 +430,7 @@ const defaultRouter = {
action('nextRouter.events.emit')(...args);
},
},
// The locale should be configured [globally](https://storybook.js.org/docs/react/essentials/toolbars-and-globals#globals)
locale: globals?.locale,
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved
asPath: '/',
basePath: '/',
Expand Down