From bc77248b11f02ceab67eeaf4c5fe721423d72471 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Fri, 17 Mar 2023 10:30:04 +1100 Subject: [PATCH 1/2] Don't assume `frameworkOptions` will be an object --- code/lib/react-dom-shim/src/preset.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/code/lib/react-dom-shim/src/preset.ts b/code/lib/react-dom-shim/src/preset.ts index 846bbca678b0..7fd9ac5aeeb4 100644 --- a/code/lib/react-dom-shim/src/preset.ts +++ b/code/lib/react-dom-shim/src/preset.ts @@ -3,9 +3,8 @@ import type { Options } from '@storybook/types'; import { version } from 'react-dom/package.json'; export const webpackFinal = async (config: any, options: Options) => { - const { legacyRootApi } = await options.presets.apply<{ legacyRootApi?: boolean }>( - 'frameworkOptions' - ); + const { legacyRootApi } = + (await options.presets.apply<{ legacyRootApi?: boolean }>('frameworkOptions')) || {}; const isReact18 = version.startsWith('18') || version.startsWith('0.0.0'); const useReact17 = legacyRootApi ?? !isReact18; @@ -24,9 +23,8 @@ export const webpackFinal = async (config: any, options: Options) => { }; export const viteFinal = async (config: any, options: Options) => { - const { legacyRootApi } = await options.presets.apply<{ legacyRootApi?: boolean }>( - 'frameworkOptions' - ); + const { legacyRootApi } = + (await options.presets.apply<{ legacyRootApi?: boolean }>('frameworkOptions')) || {}; const isReact18 = version.startsWith('18') || version.startsWith('0.0.0'); const useReact17 = legacyRootApi || !isReact18; From cc7b5b650f6962b78dd2679be3495919f56e87fe Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Fri, 17 Mar 2023 10:33:51 +1100 Subject: [PATCH 2/2] Type a little more carefully --- code/lib/react-dom-shim/src/preset.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/lib/react-dom-shim/src/preset.ts b/code/lib/react-dom-shim/src/preset.ts index 7fd9ac5aeeb4..cfd44f567649 100644 --- a/code/lib/react-dom-shim/src/preset.ts +++ b/code/lib/react-dom-shim/src/preset.ts @@ -4,7 +4,7 @@ import { version } from 'react-dom/package.json'; export const webpackFinal = async (config: any, options: Options) => { const { legacyRootApi } = - (await options.presets.apply<{ legacyRootApi?: boolean }>('frameworkOptions')) || {}; + (await options.presets.apply<{ legacyRootApi?: boolean } | null>('frameworkOptions')) || {}; const isReact18 = version.startsWith('18') || version.startsWith('0.0.0'); const useReact17 = legacyRootApi ?? !isReact18; @@ -24,7 +24,7 @@ export const webpackFinal = async (config: any, options: Options) => { export const viteFinal = async (config: any, options: Options) => { const { legacyRootApi } = - (await options.presets.apply<{ legacyRootApi?: boolean }>('frameworkOptions')) || {}; + (await options.presets.apply<{ legacyRootApi?: boolean } | null>('frameworkOptions')) || {}; const isReact18 = version.startsWith('18') || version.startsWith('0.0.0'); const useReact17 = legacyRootApi || !isReact18;