You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Additional context
Originally I thought this was related to #15223 but it appears to be a separate issue that results in the same error message.
We use a third party hook that triggers suspense while loading some data. If a story function uses that hook, then you get this error. Some debugging showed it failing on this code in jsxDecorator:
export var jsxDecorator = function jsxDecorator(storyFn, context) {
var _context$parameters$d2, _context$parameters$d3;
var channel = addons.getChannel();
var skip = skipJsxRender(context);
var story = storyFn(); // <<<--- it fails here since the storyFn throws a promise to trigger suspense
var jsx = '';
useEffect(function () {
if (!skip) channel.emit(SNIPPET_RENDERED, (context || {}).id, jsx);
}); // We only need to render JSX if the source block is actually going to
// consume it. Otherwise it's just slowing us down.
if (skip) {
return story;
}
Since the storyFn throws a promise to trigger suspense (even though I have a decorator setup with Suspense) it causes the useEffect to never be called until the Suspense is resolved, then it rerenders and storyFn renders fine, but now there is an extra useEffect call so you get the "Rendered more hooks than during the previous render.". It essentially makes the useEffect conditional based on the status of the Suspense.
I don't see any reason the storyFn has to be called above the useEffect, so I plan to submit a PR to move the storyFn call below the useEffect call. I manually made this change in node_modules in my local storybook and that fixed the problem for these stories that use this hook.
it works fine if the hook is called by a component in the story, it only fails if the story function itself uses the hook directly.
The text was updated successfully, but these errors were encountered:
If a story function triggers Suspense by throwing a promise liike
some third party hooks do, the story will fail to render
because the useEffect is skipped the first time and then
run the second time, resulting in the
"Rendered more hooks than during the previous render." error
This runs the story function after the useEffect hook so the same number of hooks
are run whether it triggers suspense or not, and in keeping
with the guidelines on not conditionally running hooks
Describe the bug
If a story function triggers suspense then the story errors with "Rendered more hooks than during the previous render."
To Reproduce
I have created a repro using the cra template. I will upload it and post it shortly once I clean it up a bit.
System
Additional context
Originally I thought this was related to #15223 but it appears to be a separate issue that results in the same error message.
We use a third party hook that triggers suspense while loading some data. If a story function uses that hook, then you get this error. Some debugging showed it failing on this code in jsxDecorator:
Since the
storyFn
throws a promise to trigger suspense (even though I have a decorator setup with Suspense) it causes the useEffect to never be called until the Suspense is resolved, then it rerenders and storyFn renders fine, but now there is an extra useEffect call so you get the "Rendered more hooks than during the previous render.". It essentially makes the useEffect conditional based on the status of the Suspense.I don't see any reason the storyFn has to be called above the useEffect, so I plan to submit a PR to move the storyFn call below the useEffect call. I manually made this change in node_modules in my local storybook and that fixed the problem for these stories that use this hook.
it works fine if the hook is called by a component in the story, it only fails if the story function itself uses the hook directly.
The text was updated successfully, but these errors were encountered: