react-native: React native fails with JSON.serialization issue
Describe the bug
Default configuration with sb stopped working after beta.25
To Reproduce Steps to reproduce the behavior:
npx react-native init testSB --template react-native-template-typescriptnpx -p @storybook/cli sb init --type react_native- Launch the app
- Launch the storybook server
Expected behavior Should not throw error
Screenshots

System:
Environment Info:
System:
OS: macOS 10.15.2
CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Binaries:
Node: 10.16.3 - /var/folders/xx/4pg__j5s58585b86mzz27z540000gn/T/fnm-shell-1707442/bin/node
Yarn: 1.21.1 - ~/.yarn/bin/yarn
npm: 6.9.0 - /var/folders/xx/4pg__j5s58585b86mzz27z540000gn/T/fnm-shell-1707442/bin/npm
Browsers:
Chrome: 79.0.3945.88
Safari: 13.0.4
npmPackages:
@storybook/addon-actions: 5.3.0-beta.25 => 5.3.0-beta.25
@storybook/addon-links: 5.3.0-beta.25 => 5.3.0-beta.25
@storybook/addons: 5.3.0-beta.25 => 5.3.0-beta.25
@storybook/react-native: 5.3.0-beta.25 => 5.3.0-beta.25
@storybook/react-native-server: 5.3.0-beta.25 => 5.3.0-beta.25
Additional context
It still works after downgrade to beta.25 and it stops working after beta.26 and up.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 10
- Comments: 27 (5 by maintainers)
Commits related to this issue
- Patch for Issue 9294 Patch was suggested here: https://github.com/storybookjs/storybook/issues/9294#issuecomment-580582681 Credit: @arlyon — committed to brotsky/storybook by brotsky 4 years ago
Thx @doctyper - it works for me too!
My 5 cents to folks who are not familiar with patches. To apply the suggested patch (with
npm):npm i patch-packagepackage.jsonto apply the patch after every install:"postinstall": "patch-packagehooks.currentContext = context;withhooks.currentContext = Object.assign({}, context, { hooks: null });in the filenode_modules/@storybook/addons/dist/hooks.jsnpx patch-package @storybook/addons@storybook+addons+{VERSION}.patchin thepatchesfolder will be created and applied every time you runnpm installI just ran into this issue as well.
The error comes from the use of json-fn, which does not guard against circular references in JSON objects.
There is a circular reference in
hooks.ts.contextincludes a reference tohooks, which has a parametercurrentContext, which itself includes a reference tohooks, hence the circular ref.I’m using the following patch to workaround the issue:
Hey, I’ve created a PR to fix it in the main storybook repo.
We still are in the middle of migrating out React Native from Storybook monorepo, so I can’t promise when exactly the fix will be available, but I will try to get it out as soon as I can.
I am sorry that RN Storybook was abandoned for a while. Soon RN Storybook is going to be stable (that is why we are moving it out of main monorepo) and issues like these should stop popping up.
+1
Hi @jonathanmachado , if you need this fixed urgently, there is already a working patch in this thread, posted by jenskuhrjorgensen.
Thanks @jenskuhrjorgensen for the explanation of how to create patches! That worked perfectly for me!
@simonepizzamiglio you should add it as a dependency and then, in your package.json scripts phase add the following:
"scripts": { ... "postinstall": "patch-package", ... }This way, every time you run a yarn install, the patch will be applied afterwards.@jenskuhrjorgensen you still need to install
patch-packagein your dependencies though?@arlyon Thanks for posting that diff! It worked for me!
Hopefully, the next version fixes this issue. This has been a huge headache for me!
I can confirm that this fix ‘works’ but can be subtly buggy. For my purposes it is “good enough” to tide me over.
Great! 😃
Storybook 5.3.14 fixed the issue for me. Thanks @Gongreg !
Hey, sadly not yet. But this is on my todo list for this week.
Any update on this issue ?
You are absolutely right, @simonepizzamiglio and @davidnuvolar. I’ve updated my previous comment - thanks!
Dealing with this issue as well. Any traction on this?
@mi5ha
Unfortunately, the proposed change doesn’t support mutation of context obtained from
useStoryContext:As an alternative, we can use
telejsonas we do inchannel-postmessage