Skip to content

Commit

Permalink
Next.js: Remove duplicate Fast Refresh plugin init
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Nov 23, 2023
1 parent bffa2db commit 3731ab0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
1 change: 0 additions & 1 deletion code/frameworks/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.23.2",
"@babel/runtime": "^7.23.2",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
"@storybook/addon-actions": "workspace:*",
"@storybook/builder-webpack5": "workspace:*",
"@storybook/core-common": "workspace:*",
Expand Down
21 changes: 9 additions & 12 deletions code/frameworks/nextjs/src/swc/loader.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { getProjectRoot } from '@storybook/core-common';
import { getVirtualModuleMapping } from '@storybook/core-webpack';
import type { Options } from '@storybook/types';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import type { Options, Preset } from '@storybook/types';
import type { NextConfig } from 'next';
import path from 'path';
import type { RuleSetRule } from 'webpack';
import semver from 'semver';
import { NextjsSWCNotSupportedError } from '@storybook/core-events/server-errors';
import { getNextjsVersion } from '../utils';

const applyFastRefresh = async (options: Options) => {
const isDevelopment = options.configType === 'DEVELOPMENT';
const framework = await options.presets.apply<Preset>('framework');
const reactOptions = typeof framework === 'object' ? framework.options : {};
return isDevelopment && (reactOptions.fastRefresh || process.env.FAST_REFRESH === 'true');
};

export const configureSWCLoader = async (
baseConfig: any,
options: Options,
Expand All @@ -23,15 +29,6 @@ export const configureSWCLoader = async (

const dir = getProjectRoot();

baseConfig.plugins = [
...baseConfig.plugins,
new ReactRefreshWebpackPlugin({
overlay: {
sockIntegration: 'whm',
},
}),
];

const virtualModules = await getVirtualModuleMapping(options);

baseConfig.module.rules = [
Expand All @@ -53,7 +50,7 @@ export const configureSWCLoader = async (
rootDir: dir,
pagesDir: `${dir}/pages`,
appDir: `${dir}/apps`,
hasReactRefresh: isDevelopment,
hasReactRefresh: applyFastRefresh(options),
nextConfig,
supportedBrowsers: require('next/dist/build/utils').getSupportedBrowsers(
dir,
Expand Down
1 change: 0 additions & 1 deletion code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6854,7 +6854,6 @@ __metadata:
"@babel/preset-typescript": "npm:^7.23.2"
"@babel/runtime": "npm:^7.23.2"
"@babel/types": "npm:^7.23.0"
"@pmmmwh/react-refresh-webpack-plugin": "npm:^0.5.11"
"@storybook/addon-actions": "workspace:*"
"@storybook/builder-webpack5": "workspace:*"
"@storybook/core-common": "workspace:*"
Expand Down

0 comments on commit 3731ab0

Please sign in to comment.