-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Next.js: Add support for Next 15 #29587
Merged
+643
−265
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
59df579
Nextjs: Add support for Next 15
yannbf a2b9245
Move nextjs stories to common template directory, add Nextjs 14 sandbox
yannbf 7cde000
fix
yannbf 800cefb
fix e2e
yannbf 6117c7c
fix parallelism
yannbf 104bfcc
rework compatibility for draft-mode
yannbf ac53a56
Merge branch 'next' into yann/next-15-support
yannbf 2ac6955
fix types
yannbf 4d3c6d9
fix types
yannbf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
import type { Configuration as WebpackConfig } from 'webpack'; | ||
|
||
import { configureCompatibilityAliases } from '../compatibility/compatibility-map'; | ||
import { configureNextExportMocks } from '../export-mocks/webpack'; | ||
|
||
export const configureAliases = (baseConfig: WebpackConfig): void => { | ||
configureNextExportMocks(baseConfig); | ||
configureCompatibilityAliases(baseConfig); | ||
|
||
baseConfig.resolve = { | ||
...(baseConfig.resolve ?? {}), | ||
alias: { | ||
...(baseConfig.resolve?.alias ?? {}), | ||
'@opentelemetry/api': 'next/dist/compiled/@opentelemetry/api', | ||
}, | ||
}; | ||
|
||
// remove warnings regarding compatibility paths | ||
baseConfig.ignoreWarnings = [ | ||
...(baseConfig.ignoreWarnings ?? []), | ||
(warning) => | ||
warning.message.includes("export 'draftMode'") && | ||
warning.message.includes('next/dist/server/request/headers'), | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import semver from 'semver'; | ||
import type { Configuration as WebpackConfig } from 'webpack'; | ||
|
||
import { addScopedAlias, getNextjsVersion } from '../utils'; | ||
import { addScopedAlias, getNextjsVersion, setAlias } from '../utils'; | ||
|
||
const mapping: Record<string, Record<string, string>> = { | ||
const mapping: Record<string, Record<string, string | boolean>> = { | ||
'<14.1.0': { | ||
// https://github.com/vercel/next.js/blob/v14.1.0/packages/next/src/shared/lib/segment.ts | ||
'next/dist/shared/lib/segment': '@storybook/nextjs/dist/compatibility/segment.compat', | ||
|
@@ -13,6 +13,11 @@ const mapping: Record<string, Record<string, string>> = { | |
'next/dist/client/components/redirect-status-code': | ||
'@storybook/nextjs/dist/compatibility/redirect-status-code.compat', | ||
}, | ||
'<15.0.0': { | ||
'next/dist/server/request/headers': 'next/dist/client/components/headers', | ||
// this path only exists from Next 15 onwards | ||
'next/dist/server/request/draft-mode': '@storybook/nextjs/dist/compatibility/draft-mode.compat', | ||
}, | ||
}; | ||
|
||
export const getCompatibilityAliases = () => { | ||
|
@@ -32,6 +37,10 @@ export const configureCompatibilityAliases = (baseConfig: WebpackConfig): void = | |
const aliases = getCompatibilityAliases(); | ||
|
||
Object.entries(aliases).forEach(([name, alias]) => { | ||
addScopedAlias(baseConfig, name, alias); | ||
if (typeof alias === 'string') { | ||
addScopedAlias(baseConfig, name, alias); | ||
} else { | ||
setAlias(baseConfig, name, alias); | ||
} | ||
}); | ||
Comment on lines
39
to
45
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. style: Consider adding error handling for unexpected alias types |
||
}; |
2 changes: 2 additions & 0 deletions
2
code/frameworks/nextjs/src/compatibility/draft-mode.compat.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Compatibility for Next 14 | ||
export { draftMode } from 'next/dist/client/components/headers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { fn } from '@storybook/test'; | ||
|
||
import * as originalHeaders from 'next/dist/client/components/headers'; | ||
// This export won't exist in Next.js 14 but it's safe because we ignore it in Webpack when applicable | ||
import { draftMode as originalDraftMode } from 'next/dist/server/request/draft-mode'; | ||
import * as headers from 'next/dist/server/request/headers'; | ||
|
||
// re-exports of the actual module | ||
export * from 'next/dist/client/components/headers'; | ||
export * from 'next/dist/server/request/headers'; | ||
|
||
// mock utilities/overrides (as of Next v14.2.0) | ||
export { headers } from './headers'; | ||
export { cookies } from './cookies'; | ||
|
||
// passthrough mocks - keep original implementation but allow for spying | ||
const draftMode = fn(originalHeaders.draftMode).mockName('draftMode'); | ||
const draftMode = fn(originalDraftMode ?? (headers as any).draftMode).mockName('draftMode'); | ||
export { draftMode }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import Font from './Font'; | ||
|
||
export default { | ||
component: Font, | ||
} as Meta<typeof Font>; | ||
|
||
type Story = StoryObj<typeof Font>; | ||
|
||
export const WithClassName: Story = { | ||
args: { | ||
variant: 'className', | ||
}, | ||
}; | ||
|
||
export const WithStyle: Story = { | ||
args: { | ||
variant: 'style', | ||
}, | ||
}; | ||
|
||
export const WithVariable: Story = { | ||
args: { | ||
variant: 'variable', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
style: ignoring warnings about missing draftMode export could mask real issues if the export path changes again in future Next.js versions