-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Next.js: Implement next redirect and the RedirectBoundary
- Loading branch information
Showing
8 changed files
with
254 additions
and
1,222 deletions.
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
32 changes: 32 additions & 0 deletions
32
code/frameworks/nextjs/src/compatibility/compatibility-map.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,32 @@ | ||
import type { Configuration as WebpackConfig } from 'webpack'; | ||
import semver from 'semver'; | ||
import { getNextjsVersion, addScopedAlias } from '../utils'; | ||
|
||
const mapping: Record<string, Record<string, string>> = { | ||
'<14.0.0': { | ||
'next/dist/shared/lib/segment': '@storybook/nextjs/dist/compatibility/segment.compat', | ||
'next/dist/client/components/redirect-status-code': | ||
'@storybook/nextjs/dist/compatibility/redirect-status-code.compat', | ||
}, | ||
}; | ||
|
||
export const getCompatibilityAliases = () => { | ||
const version = getNextjsVersion(); | ||
const result: Record<string, string> = {}; | ||
|
||
Object.keys(mapping).filter((key) => { | ||
if (semver.intersects(version, key)) { | ||
Object.assign(result, mapping[key]); | ||
} | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
export const configureCompatibilityAliases = (baseConfig: WebpackConfig): void => { | ||
const aliases = getCompatibilityAliases(); | ||
|
||
Object.entries(aliases).forEach(([name, alias]) => { | ||
addScopedAlias(baseConfig, name, alias); | ||
}); | ||
}; |
6 changes: 6 additions & 0 deletions
6
code/frameworks/nextjs/src/compatibility/redirect-status-code.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,6 @@ | ||
// Compatibility for Next 13 | ||
export enum RedirectStatusCode { | ||
SeeOther = 303, | ||
TemporaryRedirect = 307, | ||
PermanentRedirect = 308, | ||
} |
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,8 @@ | ||
// Compatibility for Next 13 | ||
// from https://github.com/vercel/next.js/blob/606f9ff7903b58da51aa043bfe71cd7b6ea306fd/packages/next/src/shared/lib/segment.ts#L4 | ||
export function isGroupSegment(segment: string) { | ||
return segment[0] === '(' && segment.endsWith(')'); | ||
} | ||
|
||
export const PAGE_SEGMENT_KEY = '__PAGE__'; | ||
export const DEFAULT_SEGMENT_KEY = '__DEFAULT__'; |
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.