Skip to content

Commit

Permalink
fix: dont mutate the context
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyhw committed Oct 15, 2024
1 parent 8c7d026 commit 93489e8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/react-native/metro/withStorybook.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ module.exports = (
const isStorybookModule =
moduleName.startsWith('storybook') || moduleName.startsWith('@storybook');

if (isStorybookModule) {
context.unstable_enablePackageExports = true;
context.unstable_conditionNames = ['import'];
}

const resolveResult = resolveFunction(context, moduleName, platform);
const theContext = isStorybookModule
? {
...context,
unstable_enablePackageExports: true,
unstable_conditionNames: ['import'],
}
: context;

const resolveResult = resolveFunction(theContext, moduleName, platform);

// workaround for template files with invalid imports
if (resolveResult?.filePath?.includes?.('@storybook/react/template/cli')) {
Expand Down

2 comments on commit 93489e8

@jvliwanag
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was wondering about this as well when I first saw. But when tested, metro seemed to recreate the context anyway so mutation was ok. Then again, I imagine, best be safe :)

@dannyhw
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this was what I saw doing it in expo, then someone reached out about the rncli version being broken and I noticed that was the issue.

I was just thinking that mutating it would be faster than copying the object but in the end it ended up being a mistake

Please sign in to comment.