Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0] 6.0.1-alpha.1 does not work with Expo #247

Closed
lauriharpf opened this issue Jul 28, 2021 · 16 comments
Closed

[6.0] 6.0.1-alpha.1 does not work with Expo #247

lauriharpf opened this issue Jul 28, 2021 · 16 comments
Assignees
Labels
6.5 bug Something isn't working

Comments

@lauriharpf
Copy link
Contributor

Describe the bug
Attempting to follow the 6.0 alpha test instructions with Expo causes an error:

Failed to compile.
/Users/lauriharpf/Repos/lauriharpf/appName/node_modules/@storybook/react-native/dist/preview/Preview.js 12:14
Module parse failed: Unexpected token (12:14)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const STORAGE_KEY = 'lastOpenedStory';
| export default class Preview {
>     _clientApi;
|     _storyStore;
|     _addons;

To Reproduce
Do these steps (slightly modified from the script version of the 6.0 alpha test instructions).

npm install --global expo-cli
expo init appName
(select blank TypeScript template)
cd appName

yarn add @storybook/react-native@next \
            @react-native-async-storage/async-storage \
            @storybook/addon-ondevice-actions@next \
            @storybook/addon-ondevice-controls@next \
            @storybook/addon-ondevice-backgrounds@next \
            @storybook/addon-ondevice-notes@next \
            @storybook/addon-actions \
            @react-native-community/datetimepicker \
            @react-native-community/slider \
            @storybook/addon-controls

echo "/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */
module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
  resolver: {
    resolverMainFields: ['sbmodern', 'main'],
  },
};" > metro.config.js;

mkdir .storybook;
mkdir components;
echo "module.exports = {
  stories: [
    './components/**/*.stories.?(ts|tsx|js|jsx)'
  ],
   addons: [
    '@storybook/addon-ondevice-notes',
    '@storybook/addon-ondevice-controls',
    '@storybook/addon-ondevice-backgrounds',
    '@storybook/addon-ondevice-actions',
  ],
};" > .storybook/main.js;

echo "import {withBackgrounds} from '@storybook/addon-ondevice-backgrounds';
export const decorators = [withBackgrounds];
export const parameters = {
  backgrounds: [
    {name: 'plain', value: 'white', default: true},
    {name: 'warm', value: 'hotpink'},
    {name: 'cool', value: 'deepskyblue'},
  ],
};" > .storybook/preview.js;

echo "import AsyncStorage from '@react-native-async-storage/async-storage';
import { getStorybookUI } from '@storybook/react-native';
import './storybook.requires';
const StorybookUIRoot = getStorybookUI({
  asyncStorage: AsyncStorage,
});
export default StorybookUIRoot;" > Storybook.tsx;

echo "import StorybookUIRoot from './Storybook';
export { StorybookUIRoot as default };" > App.tsx;

node -e 'const fs = require("fs");
const packageJSON = require("./package.json");
packageJSON.scripts = {
    ...packageJSON.scripts,
    prestart: "sbn-get-stories",
    "storybook-watcher": "sbn-watcher"
};
fs.writeFile("./package.json", JSON.stringify(packageJSON, null, 2), function writeJSON(err) {
  if (err) return console.log(err);
  console.log(JSON.stringify(packageJSON));
  console.log("writing to " + "./package.json");
});';

mkdir components/Button;
echo "import React from 'react';
import {TouchableOpacity, Text, StyleSheet} from 'react-native';
interface MyButtonProps {
  onPress: () => void;
  text: string;
}
export const MyButton = ({onPress, text}: MyButtonProps) => {
  return (
    <TouchableOpacity style={styles.container} onPress={onPress}>
      <Text style={styles.text}>{text}</Text>
    </TouchableOpacity>
  );
};
const styles = StyleSheet.create({
  container: {
    paddingHorizontal: 16,
    paddingVertical: 8,
    backgroundColor: 'violet',
  },
  text: {color: 'black'},
});
" > components/Button/Button.tsx;

echo "import React from 'react';
import {ComponentStory, ComponentMeta} from '@storybook/react-native';
import {MyButton} from './Button';
const MyButtonMeta: ComponentMeta<typeof MyButton> = {
  title: 'MyButton',
  component: MyButton,
  argTypes: {
    onPress: {action: 'pressed the button'},
  },
  args: {
    text: 'Hello world',
  },
};
export default MyButtonMeta;
type MyButtonStory = ComponentStory<typeof MyButton>;
export const Basic: MyButtonStory = args => <MyButton {...args} />;
" > components/Button/Button.stories.tsx;

yarn sbn-get-stories;

yarn web

This causes the error regarding node_modules/@storybook/react-native/dist/preview/Preview.js.

Expected behavior
No error should occur.

System:

Environment Info:

  System:
    OS: macOS 11.4
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 16.4.0 - ~/.nvm/versions/node/v16.4.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v16.4.0/bin/yarn
    npm: 7.19.0 - ~/.nvm/versions/node/v16.4.0/bin/npm
  Browsers:
    Chrome: 92.0.4515.107
    Safari: 14.1.1
  npmPackages:
    @storybook/addon-actions: ^6.3.6 => 6.3.6 
    @storybook/addon-controls: ^6.3.6 => 6.3.6 
    @storybook/addon-ondevice-actions: ^6.0.1-alpha.0 => 6.0.1-alpha.0 
    @storybook/addon-ondevice-backgrounds: ^6.0.1-alpha.0 => 6.0.1-alpha.0 
    @storybook/addon-ondevice-controls: ^6.0.1-alpha.0 => 6.0.1-alpha.0 
    @storybook/addon-ondevice-notes: ^6.0.1-alpha.0 => 6.0.1-alpha.0 
    @storybook/react-native: ^6.0.1-alpha.1 => 6.0.1-alpha.1 

Additional context
The problem looks related to the class properties in node_modules/@storybook/react-native/dist/preview/Preview.js. The 6.0.1-alpha.1 version has class properties. The corresponding 5.3.25 code does not have them.

This might be resolved by removing "target": "ESNext", and "lib": ["ESNext"], from the 6.0 tsconfig.json: https://github.com/storybookjs/react-native/blob/next-6.0/app/react-native/tsconfig.json#L9 . The 5.3.25 version of tsconfig.json does not have those, so Typescript defaults to output ES3 code. That's probably the best choice for the code we distribute in the NPM packages, as ES3 code should be runnable by pretty much anything without additional transpilation.

@dannyhw
Copy link
Member

dannyhw commented Jul 28, 2021

Personally I'd like to avoid anything lower than es6, there have been many issues caused by corejs polyfills (#20) and I think that es6 is already supported by the majority of devices at this point. Also I think this will only effect react-native on web and I don't really think its important to support internet explorer since it's on the way out.

@dannyhw
Copy link
Member

dannyhw commented Jul 28, 2021

Does the ios/android app still work? From the log it looks like you're using the web version.

@lauriharpf
Copy link
Contributor Author

Does the ios/android app still work? From the log it looks like you're using the web version.

Both yarn ios and yarn android fail, but the error is different - it is about a missing module:

Failed building JavaScript bundle.
Unable to resolve module crypto from /Users/lauriharpf/Repos/lauriharpf/appName/node_modules/uuid/lib/rng.js: crypto could not be found within the project.

Screen Shot 2021-07-30 at 12 59 12

After finding an informative Stackoverflow thread on this (https://stackoverflow.com/questions/52697108/unable-to-resolve-module-crypto-in-reactnative), I tried adding the react-native-crypto-dependency with the instructions at https://www.npmjs.com/package/react-native-crypto:

yarn add react-native-crypto
yarn add react-native-randombytes
yarn add tradle/rn-nodeify
./node_modules/.bin/rn-nodeify --hack --install
(Added import './shim.js'
import crypto from 'crypto' to App.tsx)

However, this didn't resolve the issue. The yarn why report on uuid (which uses ´crypto`) is slightly confusing, as it doesn't reveal any linkage to React Native Storybook:

lauriharpf@Lauris-MacBook-Pro appName % yarn why uuid
yarn why v1.22.10
[1/4] 🤔  Why do we have the module "uuid"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "uuid@3.4.0"
info Has been hoisted to "uuid"
info Reasons this module exists
   - Hoisted from "expo#uuid"
   - Hoisted from "expo#expo-constants#uuid"
   - Hoisted from "expo#expo-file-system#uuid"
   - Hoisted from "react-native#@react-native-community#cli-platform-ios#xcode#uuid"
info Disk size without dependencies: "92KB"
info Disk size with unique dependencies: "92KB"
info Disk size with transitive dependencies: "92KB"
info Number of shared dependencies: 0
=> Found "xcode#uuid@7.0.3"
info This module exists because "xcode" depends on it.
info Disk size without dependencies: "256KB"
info Disk size with unique dependencies: "256KB"
info Disk size with transitive dependencies: "256KB"
info Number of shared dependencies: 0
✨  Done in 0.60s.

@lauriharpf
Copy link
Contributor Author

Personally I'd like to avoid anything lower than es6, there have been many issues caused by corejs polyfills (#20) and I think that es6 is already supported by the majority of devices at this point. Also I think this will only effect react-native on web and I don't really think its important to support internet explorer since it's on the way out.

Thanks, wasn't aware that dropping the target would cause issues. Got the original error message when attempting to run yarn web that launched in a Brave browser window.

@dannyhw
Copy link
Member

dannyhw commented Jul 30, 2021

React native crypto? Is this a bitcoin miner or what? 😂

I guess that crypto is being used as a random number generator for uuid? Weird that uuid is included as part of expo though. From that same stackoverflow link someone suggested crypto-js so maybe that would work? Looks like a polyfill for the nodejs crypto module.

I think I'll install this locally as well and investigate a bit.

@lauriharpf
Copy link
Contributor Author

React native crypto? Is this a bitcoin miner or what? 😂

My thoughts as well 😂

I guess that crypto is being used as a random number generator for uuid? Weird that uuid is included as part of expo though. From that same stackoverflow link someone suggested crypto-js so maybe that would work? Looks like a polyfill for the nodejs crypto module.

Yeah. If you install this locally, then the problematic file node_modules/uuid/lib/rng.js looks like this:

// Unique ID creation requires a high quality random # generator.  In node.js
// this is pretty straight-forward - we use the crypto API.

var crypto = require('crypto');

module.exports = function nodeRNG() {
  return crypto.randomBytes(16);
};

Adding crypto-js might not be enough due to the require('crypto'), but let's see. This might also be an issue related to the Expo & RN versions I happened to get, to the Node version or something else entirely. For reference, here are the Expo and React dependencies from the package.json that Expo created:

    "expo": "~42.0.1",
     "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",

@dannyhw
Copy link
Member

dannyhw commented Jul 31, 2021

I saw someone comment somewhere that after updating npm and node it got resolved. Maybe it doesn't apply here but could be worth trying. What version of node are you using?

Could also try expo-crypto
https://docs.expo.dev/versions/latest/sdk/crypto/

@dannyhw
Copy link
Member

dannyhw commented Jul 31, 2021

maybe using expo install instead of yarn install would make a difference?
__
nevermind I tried it and it didn't work.

Check this out though, seems to be a common issue.
uuidjs/uuid#375 (comment)

__

Initially I was looking into this thinking that maybe it's an expo bug or something because there is no reference to crypto or uuid in the project. However I was a able to run storybook without any addons and things seemed to work and then once I added on-device-controls I started getting this bug again. I've been running into a wall with this for a while so I'll come back to it another day 😅 .

@dannyhw dannyhw added bug Something isn't working 6.5 labels Jul 31, 2021
@lauriharpf
Copy link
Contributor Author

@dannyhw, troubleshooted this a bit today. This seems to be the part that breaks yarn ios and yarn android on Expo:

echo "/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */
module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
  resolver: {
    resolverMainFields: ['sbmodern', 'main'],
  },
};" > metro.config.js;

If I omit that and only do this:

npm install --global expo-cli
expo init appName
(select blank TypeScript template)
cd appName

yarn add @storybook/react-native@next \
            @react-native-async-storage/async-storage \
            @storybook/addon-ondevice-actions@next \
            @storybook/addon-ondevice-controls@next \
            @storybook/addon-ondevice-backgrounds@next \
            @storybook/addon-ondevice-notes@next \
            @storybook/addon-actions \
            @react-native-community/datetimepicker \
            @react-native-community/slider \
            @storybook/addon-controls

mkdir .storybook;
mkdir components;
echo "module.exports = {
  stories: [
    './components/**/*.stories.?(ts|tsx|js|jsx)'
  ],
   addons: [
    '@storybook/addon-ondevice-notes',
    '@storybook/addon-ondevice-controls',
    '@storybook/addon-ondevice-backgrounds',
    '@storybook/addon-ondevice-actions',
  ],
};" > .storybook/main.js;

echo "import {withBackgrounds} from '@storybook/addon-ondevice-backgrounds';
export const decorators = [withBackgrounds];
export const parameters = {
  backgrounds: [
    {name: 'plain', value: 'white', default: true},
    {name: 'warm', value: 'hotpink'},
    {name: 'cool', value: 'deepskyblue'},
  ],
};" > .storybook/preview.js;

echo "import AsyncStorage from '@react-native-async-storage/async-storage';
import { getStorybookUI } from '@storybook/react-native';
import './storybook.requires';
const StorybookUIRoot = getStorybookUI({
  asyncStorage: AsyncStorage,
});
export default StorybookUIRoot;" > Storybook.tsx;

echo "import StorybookUIRoot from './Storybook';
export { StorybookUIRoot as default };" > App.tsx;

node -e 'const fs = require("fs");
const packageJSON = require("./package.json");
packageJSON.scripts = {
    ...packageJSON.scripts,
    prestart: "sbn-get-stories",
    "storybook-watcher": "sbn-watcher"
};
fs.writeFile("./package.json", JSON.stringify(packageJSON, null, 2), function writeJSON(err) {
  if (err) return console.log(err);
  console.log(JSON.stringify(packageJSON));
  console.log("writing to " + "./package.json");
});';

mkdir components/Button;
echo "import React from 'react';
import {TouchableOpacity, Text, StyleSheet} from 'react-native';
interface MyButtonProps {
  onPress: () => void;
  text: string;
}
export const MyButton = ({onPress, text}: MyButtonProps) => {
  return (
    <TouchableOpacity style={styles.container} onPress={onPress}>
      <Text style={styles.text}>{text}</Text>
    </TouchableOpacity>
  );
};
const styles = StyleSheet.create({
  container: {
    paddingHorizontal: 16,
    paddingVertical: 8,
    backgroundColor: 'violet',
  },
  text: {color: 'black'},
});
" > components/Button/Button.tsx;

echo "import React from 'react';
import {ComponentStory, ComponentMeta} from '@storybook/react-native';
import {MyButton} from './Button';
const MyButtonMeta: ComponentMeta<typeof MyButton> = {
  title: 'MyButton',
  component: MyButton,
  argTypes: {
    onPress: {action: 'pressed the button'},
  },
  args: {
    text: 'Hello world',
  },
};
export default MyButtonMeta;
type MyButtonStory = ComponentStory<typeof MyButton>;
export const Basic: MyButtonStory = args => <MyButton {...args} />;
" > components/Button/Button.stories.tsx;

yarn sbn-get-stories

then both yarn ios and yarn android work. yarn web still fails for me with

Failed to compile.
/Users/lauriharpf/Repos/lauriharpf/appName/node_modules/@storybook/react-native/dist/preview/Preview.js 12:14
Module parse failed: Unexpected token (12:14)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const STORAGE_KEY = 'lastOpenedStory';
| export default class Preview {
>     _clientApi;
|     _storyStore;
|     _addons;

but I'm unsure how important that is. There's a visual issue on Android: the app paints outside the safe area (see screenshots below). This issue doesn't appear on iOS.

Screen Shot 2021-08-10 at 21 51 24

Screen Shot 2021-08-10 at 21 51 08

lauriharpf added a commit to lauriharpf/react-native that referenced this issue Aug 10, 2021
…ctions on how to set up with Expo.

Also fixes linter warning in README.md.
@lauriharpf lauriharpf self-assigned this Aug 10, 2021
@lauriharpf
Copy link
Contributor Author

We discussed the need for metro.config.js with @dannyhw. Seems that omitting it (as I suggested above) would cause issues with promises, see #57 .

After some experimenting and reading Expo's customizing Metro docs , this looks like a promising Expo version of the metro.config.js:

const { getDefaultConfig } = require("expo/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.resolver.resolverMainFields = [
  "sbmodern",
  ...defaultConfig.resolver.resolverMainFields,
];
defaultConfig.transformer.getTransformOptions = async () => ({
  transform: {
    experimentalImportSupport: false,
    inlineRequires: false,
  },
});
module.exports = defaultConfig;

So, the whole setup for Expo would be

npm install --global expo-cli
expo init appName
(select blank TypeScript template)
cd appName

yarn add @storybook/react-native@next \
            @react-native-async-storage/async-storage \
            @storybook/addon-ondevice-actions@next \
            @storybook/addon-ondevice-controls@next \
            @storybook/addon-ondevice-backgrounds@next \
            @storybook/addon-ondevice-notes@next \
            @storybook/addon-actions \
            @react-native-community/datetimepicker \
            @react-native-community/slider \
            @storybook/addon-controls

echo "const { getDefaultConfig } = require('expo/metro-config');

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.resolver.resolverMainFields = [
  'sbmodern',
  ...defaultConfig.resolver.resolverMainFields,
];
defaultConfig.transformer.getTransformOptions = async () => ({
  transform: {
    experimentalImportSupport: false,
    inlineRequires: false,
  },
});
module.exports = defaultConfig;
" > metro.config.js;

mkdir .storybook;
mkdir components;
echo "module.exports = {
  stories: [
    './components/**/*.stories.?(ts|tsx|js|jsx)'
  ],
   addons: [
    '@storybook/addon-ondevice-notes',
    '@storybook/addon-ondevice-controls',
    '@storybook/addon-ondevice-backgrounds',
    '@storybook/addon-ondevice-actions',
  ],
};" > .storybook/main.js;

echo "import {withBackgrounds} from '@storybook/addon-ondevice-backgrounds';
export const decorators = [withBackgrounds];
export const parameters = {
  backgrounds: [
    {name: 'plain', value: 'white', default: true},
    {name: 'warm', value: 'hotpink'},
    {name: 'cool', value: 'deepskyblue'},
  ],
};" > .storybook/preview.js;

echo "import AsyncStorage from '@react-native-async-storage/async-storage';
import { getStorybookUI } from '@storybook/react-native';
import './storybook.requires';
const StorybookUIRoot = getStorybookUI({
  asyncStorage: AsyncStorage,
});
export default StorybookUIRoot;" > Storybook.tsx;

echo "import StorybookUIRoot from './Storybook';
export { StorybookUIRoot as default };" > App.tsx;

node -e 'const fs = require("fs");
const packageJSON = require("./package.json");
packageJSON.scripts = {
    ...packageJSON.scripts,
    prestart: "sbn-get-stories",
    "storybook-watcher": "sbn-watcher"
};
fs.writeFile("./package.json", JSON.stringify(packageJSON, null, 2), function writeJSON(err) {
  if (err) return console.log(err);
  console.log(JSON.stringify(packageJSON));
  console.log("writing to " + "./package.json");
});';

mkdir components/Button;
echo "import React from 'react';
import {TouchableOpacity, Text, StyleSheet} from 'react-native';
interface MyButtonProps {
  onPress: () => void;
  text: string;
}
export const MyButton = ({onPress, text}: MyButtonProps) => {
  return (
    <TouchableOpacity style={styles.container} onPress={onPress}>
      <Text style={styles.text}>{text}</Text>
    </TouchableOpacity>
  );
};
const styles = StyleSheet.create({
  container: {
    paddingHorizontal: 16,
    paddingVertical: 8,
    backgroundColor: 'violet',
  },
  text: {color: 'black'},
});
" > components/Button/Button.tsx;

echo "import React from 'react';
import {ComponentStory, ComponentMeta} from '@storybook/react-native';
import {MyButton} from './Button';
const MyButtonMeta: ComponentMeta<typeof MyButton> = {
  title: 'MyButton',
  component: MyButton,
  argTypes: {
    onPress: {action: 'pressed the button'},
  },
  args: {
    text: 'Hello world',
  },
};
export default MyButtonMeta;
type MyButtonStory = ComponentStory<typeof MyButton>;
export const Basic: MyButtonStory = args => <MyButton {...args} />;
" > components/Button/Button.stories.tsx;

yarn sbn-get-stories

With this metro.config.js, promises seemed to work on Expo. Without it, they failed.

Some issues still seem to persist, though. The Promise example https://github.com/storybookjs/react-native/blob/next-6.0/examples/native/components/PromiseTest/Button.stories.tsx wouldn't run as-is on Expo. Instead, it errored out due to the React hooks:

Warning: React has detected a change in the order of Hooks called by StoryView. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks

   Previous render            Next render
   ------------------------------------------------------
1. useState                   useState
2. useEffect                  useEffect
3. undefined                  useState
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    in StoryView (at OnDeviceUI.js:92)
    in RCTView (at View.js:34)
    in View (created by Context.Consumer)
    in emotion(View) (at OnDeviceUI.js:91)
    in RCTView (at View.js:34)
    in View (at createAnimatedComponent.js:165)
    in AnimatedComponent (at createAnimatedComponent.js:215)
    in ForwardRef(AnimatedComponentWrapper) (at OnDeviceUI.js:90)
    in RCTView (at View.js:34)
    in View (at createAnimatedComponent.js:165)
    in AnimatedComponent (at createAnimatedComponent.js:215)
    in ForwardRef(AnimatedComponentWrapper) (at OnDeviceUI.js:89)
    in RCTView (at View.js:34)
    in View (at absolute-positioned-keyboard-aware-view.js:13)
    in RCTView (at View.js:34)
    in View (at absolute-positioned-keyboard-aware-view.js:12)
    in AbsolutePositionedKeyboardAwareView (at OnDeviceUI.js:88)
    in RCTView (at View.js:34)
    in View (at KeyboardAvoidingView.js:204)
    in KeyboardAvoidingView (at OnDeviceUI.js:87)
    in RCTSafeAreaView (at SafeAreaView.js:51)
    in ForwardRef(SafeAreaView) (at OnDeviceUI.js:86)
    in OnDeviceUI (at Preview.js:59)
    in ThemeProvider (at Preview.js:58)
    in Unknown (created by ExpoRoot)
    in ExpoRoot (at renderApplication.js:45)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:106)
    in DevAppContainer (at AppContainer.js:121)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)
at components/Button/ButtonPromise.stories.tsx:9:30 in storiesOf.add$argument_1
at node_modules/@storybook/client-api/dist/modern/story_store.js:505:37 in finalStoryFn
at node_modules/@storybook/addons/dist/modern/hooks.js:116:17 in <anonymous>
at node_modules/@storybook/client-api/dist/modern/decorators.js:47:27 in <anonymous>
at node_modules/@storybook/addon-ondevice-backgrounds/dist/index.js:46:140 in addons_1.makeDecorator$argument_0.wrapper
at node_modules/@storybook/addons/dist/modern/make-decorator.js:18:18 in <anonymous>
at node_modules/@storybook/addons/dist/modern/make-decorator.js:27:13 in <anonymous>
at node_modules/@storybook/addons/dist/modern/hooks.js:116:17 in <anonymous>
at node_modules/@storybook/client-api/dist/modern/decorators.js:19:29 in <anonymous>
at node_modules/@storybook/client-api/dist/modern/decorators.js:53:36 in <anonymous>
at node_modules/@storybook/addons/dist/modern/hooks.js:143:26 in <anonymous>
at node_modules/@storybook/client-api/dist/modern/story_store.js:560:50 in unboundStoryFn
at node_modules/@storybook/react-native/dist/preview/components/StoryView/StoryView.js:27:60 in StoryView
at node_modules/@storybook/react-native/dist/preview/components/StoryView/StoryView.js:17:28 in loadContext

Error: Rendered more hooks than during the previous render.

This error is located at:
    in StoryView (at OnDeviceUI.js:92)
    in RCTView (at View.js:34)
    in View (created by Context.Consumer)
    in emotion(View) (at OnDeviceUI.js:91)
    in RCTView (at View.js:34)
    in View (at createAnimatedComponent.js:165)
    in AnimatedComponent (at createAnimatedComponent.js:215)
    in ForwardRef(AnimatedComponentWrapper) (at OnDeviceUI.js:90)
    in RCTView (at View.js:34)
    in View (at createAnimatedComponent.js:165)
    in AnimatedComponent (at createAnimatedComponent.js:215)
    in ForwardRef(AnimatedComponentWrapper) (at OnDeviceUI.js:89)
    in RCTView (at View.js:34)
    in View (at absolute-positioned-keyboard-aware-view.js:13)
    in RCTView (at View.js:34)
    in View (at absolute-positioned-keyboard-aware-view.js:12)
    in AbsolutePositionedKeyboardAwareView (at OnDeviceUI.js:88)
    in RCTView (at View.js:34)
    in View (at KeyboardAvoidingView.js:204)
    in KeyboardAvoidingView (at OnDeviceUI.js:87)
    in RCTSafeAreaView (at SafeAreaView.js:51)
    in ForwardRef(SafeAreaView) (at OnDeviceUI.js:86)
    in OnDeviceUI (at Preview.js:59)
    in ThemeProvider (at Preview.js:58)
    in Unknown (created by ExpoRoot)
    in ExpoRoot (at renderApplication.js:45)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:106)
    in DevAppContainer (at AppContainer.js:121)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:171:19 in handleException
at node_modules/react-native/Libraries/Core/ReactFiberErrorDialog.js:43:2 in showErrorDialog
at node_modules/@storybook/react-native/dist/preview/components/StoryView/StoryView.js:17:28 in loadContext

[Unhandled promise rejection: Error: Rendered more hooks than during the previous render.]
at components/Button/ButtonPromise.stories.tsx:9:30 in storiesOf.add$argument_1
at node_modules/@storybook/client-api/dist/modern/story_store.js:505:37 in finalStoryFn
at node_modules/@storybook/addons/dist/modern/hooks.js:116:17 in <anonymous>
at node_modules/@storybook/client-api/dist/modern/decorators.js:47:27 in <anonymous>
at node_modules/@storybook/addon-ondevice-backgrounds/dist/index.js:46:140 in addons_1.makeDecorator$argument_0.wrapper
at node_modules/@storybook/addons/dist/modern/make-decorator.js:18:18 in <anonymous>
at node_modules/@storybook/addons/dist/modern/make-decorator.js:27:13 in <anonymous>
at node_modules/@storybook/addons/dist/modern/hooks.js:116:17 in <anonymous>
at node_modules/@storybook/client-api/dist/modern/decorators.js:19:29 in <anonymous>
at node_modules/@storybook/client-api/dist/modern/decorators.js:53:36 in <anonymous>
at node_modules/@storybook/addons/dist/modern/hooks.js:143:26 in <anonymous>
at node_modules/@storybook/client-api/dist/modern/story_store.js:560:50 in unboundStoryFn
at node_modules/@storybook/react-native/dist/preview/components/StoryView/StoryView.js:27:60 in StoryView
at node_modules/@storybook/react-native/dist/preview/components/StoryView/StoryView.js:17:28 in loadContext

After removing the hooks (replacing the text changes with Alert notifications) the example ran fine on Expo.

lauriharpf added a commit to lauriharpf/react-native that referenced this issue Aug 12, 2021
@dannyhw dannyhw reopened this Aug 15, 2021
@dannyhw
Copy link
Member

dannyhw commented Aug 15, 2021

This got auto closed by merging. @lauriharpf Do you think this should be marked as resolved or are there still more things to resolve?

@lauriharpf
Copy link
Contributor Author

@dannyhw, good observation! We could still try to investigate and fix at least the hooks problem mentioned in #247 (comment) within the scope of this, as that seems like a pretty nasty one.

@cyrfer
Copy link

cyrfer commented Aug 23, 2021

I bumped into this following the v6 README as well.

I am hoping to target web. I'll give the ios and android targets a try later.

@dannyhw
Copy link
Member

dannyhw commented Sep 12, 2021

should be fixed in 6.0.1-alpha.3 which was released today

@dannyhw dannyhw closed this as completed Sep 12, 2021
dannyhw pushed a commit to raychanks/react-native that referenced this issue Feb 7, 2022
…ctions on how to set up with Expo (storybookjs#250)

* docs: Fixes storybookjs#247 by editing the v6 alpha guide with instructions on how to set up with Expo.

Also fixes linter warning in README.md.

* docs: Updated the V6 Alpha readme with the Expo metro config as discussed in storybookjs#247 (comment)
@jesse-savary
Copy link

In case anyone else ends up here while searching for a solution to React has detected a change in the order of Hooks called by StoryView, add this to .ondevice/preview.js:

const withHooks = (Story) => <Story />

export const decorators = [..., withHooks]

@dannyhw
Copy link
Member

dannyhw commented Apr 29, 2022

@jesse-savary could you open an issue regarding that problem with more detail on the error you are getting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.5 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants