From 93bc3052800e6ea66a6862191c303ed56579b539 Mon Sep 17 00:00:00 2001 From: Tyler Sticka Date: Wed, 6 Apr 2022 13:17:36 -0700 Subject: [PATCH 1/4] Partial source fix --- .storybook/preview.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.storybook/preview.js b/.storybook/preview.js index b991cbe37..679e94f40 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -56,7 +56,8 @@ export const parameters = { prepareForInline: (storyFn) => htmlToReactParser.parse(storyFn()), transformSource(src, storyContext) { try { - const storyFunction = storyContext.getOriginal(); + const storyFunction = storyContext.originalStoryFn; + if (!storyFunction) return src; const rendered = storyFunction(storyContext.args); // The twing/source-inputs-loader.js file makes it so that whenever twig templates are rendered, // the arguments and input path are stored in the window.__twig_inputs__ variable. @@ -65,7 +66,11 @@ export const parameters = { // that correspond to that output const input = window.__twig_inputs__?.get(rendered); if (!input) return src; - return makeTwigInclude(input.path, input.args); + const twigInclude = makeTwigInclude(input.path, input.args); + // When I do this, I see the source output many times... some with the + // args intact, some without args at all. Alert is a good example. + console.log(storyContext.id, storyContext.args, twigInclude); + return twigInclude; } catch { return src; } From a8046d314517a90d8121e59278ee18cd6a0214e9 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Mon, 18 Apr 2022 08:29:02 -0700 Subject: [PATCH 2/4] Fall back to storyContext.initialArgs in storybook preview --- .storybook/preview.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.storybook/preview.js b/.storybook/preview.js index 679e94f40..b9df5842b 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -58,7 +58,9 @@ export const parameters = { try { const storyFunction = storyContext.originalStoryFn; if (!storyFunction) return src; - const rendered = storyFunction(storyContext.args); + const rendered = storyFunction( + storyContext.args || storyContext.initialArgs + ); // The twing/source-inputs-loader.js file makes it so that whenever twig templates are rendered, // the arguments and input path are stored in the window.__twig_inputs__ variable. // __twig_inputs__ is a map between the output HTML and and objects with the arguments and input paths @@ -69,7 +71,6 @@ export const parameters = { const twigInclude = makeTwigInclude(input.path, input.args); // When I do this, I see the source output many times... some with the // args intact, some without args at all. Alert is a good example. - console.log(storyContext.id, storyContext.args, twigInclude); return twigInclude; } catch { return src; From 2a1591097e60603a277ffbaca96f7bfb2f761dd2 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Mon, 18 Apr 2022 08:32:47 -0700 Subject: [PATCH 3/4] Delete comment --- .storybook/preview.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.storybook/preview.js b/.storybook/preview.js index b9df5842b..d67c12136 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -68,10 +68,7 @@ export const parameters = { // that correspond to that output const input = window.__twig_inputs__?.get(rendered); if (!input) return src; - const twigInclude = makeTwigInclude(input.path, input.args); - // When I do this, I see the source output many times... some with the - // args intact, some without args at all. Alert is a good example. - return twigInclude; + return = makeTwigInclude(input.path, input.args); } catch { return src; } From f885e247affaf97e3fd820177516309b6b94c607 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Mon, 18 Apr 2022 08:33:01 -0700 Subject: [PATCH 4/4] Fix typo --- .storybook/preview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.storybook/preview.js b/.storybook/preview.js index d67c12136..13a5b96eb 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -68,7 +68,7 @@ export const parameters = { // that correspond to that output const input = window.__twig_inputs__?.get(rendered); if (!input) return src; - return = makeTwigInclude(input.path, input.args); + return makeTwigInclude(input.path, input.args); } catch { return src; }