Skip to content

Commit

Permalink
Fix next@13 next/link
Browse files Browse the repository at this point in the history
  • Loading branch information
kylegach committed Nov 17, 2022
1 parent 1dbd012 commit b8475b9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion code/frameworks/nextjs/src/preset.ts
@@ -1,5 +1,6 @@
// https://storybook.js.org/docs/react/addons/writing-presets
import { dirname, join } from 'path';
import semver from 'semver';
import type { Options, PresetProperty } from '@storybook/types';
import type { TransformOptions } from '@babel/core';
import { configureConfig } from './config/webpack';
Expand All @@ -9,7 +10,7 @@ import { configureRouting } from './routing/webpack';
import { configureStyledJsx } from './styledJsx/webpack';
import { configureStyledJsxTransforms } from './styledJsx/babel';
import { configureImages } from './images/webpack';
import { configureRuntimeNextjsVersionResolution } from './utils';
import { configureRuntimeNextjsVersionResolution, getNextjsVersion } from './utils';
import type { FrameworkOptions, StorybookConfig } from './types';
import { configureTypescript } from './config/babel';

Expand All @@ -18,6 +19,8 @@ export const addons: PresetProperty<'addons', StorybookConfig> = [
dirname(require.resolve(join('@storybook/builder-webpack5', 'package.json'))),
];

const version = getNextjsVersion();

const defaultFrameworkOptions: FrameworkOptions = {};

export const frameworkOptions = async (
Expand Down Expand Up @@ -68,6 +71,17 @@ export const config: StorybookConfig['previewAnnotations'] = (entry = []) => [
require.resolve('@storybook/nextjs/preview.js'),
];

export const env = (envConfig: PresetProperty<'env', StorybookConfig>) => {
return {
...envConfig,
// Can be removed if https://github.com/vercel/next.js/issues/42621 is resolved
...(semver.gte(version, '13.0.0') && {
// TODO: This should also respect `newNextLinkBehavior`: https://github.com/vercel/next.js/blob/07d3da102dfef65be9c13fd4b754a12eda7eded1/packages/next/server/config-shared.ts#L88
__NEXT_NEW_LINK_BEHAVIOR: 'true',
}),
};
};

// Not even sb init - automigrate - running dev
// You're using a version of Nextjs prior to v10, which is unsupported by this framework.

Expand Down

0 comments on commit b8475b9

Please sign in to comment.