From d8b658dbacdce293aef40268af4278fa7b2fd4d0 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Thu, 14 Jul 2022 17:15:55 +1000 Subject: [PATCH 1/5] Add a story to demonstrate #18477 --- .../addon-docs/container-override.stories.mdx | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/examples/official-storybook/stories/addon-docs/container-override.stories.mdx b/examples/official-storybook/stories/addon-docs/container-override.stories.mdx index d0273024461..cefd2c593f8 100644 --- a/examples/official-storybook/stories/addon-docs/container-override.stories.mdx +++ b/examples/official-storybook/stories/addon-docs/container-override.stories.mdx @@ -1,19 +1,38 @@ -import { Meta, DocsContainer, Story } from '@storybook/addon-docs'; +import { useRef } from 'react'; +import { Meta, DocsContainer, Story, ArgsTable } from '@storybook/addon-docs'; ( - -
{children}
-
- ), + container: ({ children, context }) => { + const countRef = useRef(); + countRef.current = (countRef.current || 0) + 1; + return ( + +
{children}
+

Container rendered {countRef.current} times

+

Try changing:

+ +
+ ); + }, }, }} /> +export const Component = () => { + const countRef = useRef(); + countRef.current = (countRef.current || 0) + 1; + return
Story rendered {countRef.current} times
; +}; + -
some content
+
+ + From 47c51cce5c59191f0303c69e671074e9451a313c Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Thu, 14 Jul 2022 17:19:59 +1000 Subject: [PATCH 2/5] Ensure we always re-render docs when globals change --- lib/preview-web/src/DocsRender.ts | 4 ++-- lib/preview-web/src/PreviewWeb.test.ts | 24 ++++++++++++++++++++++-- lib/preview-web/src/PreviewWeb.tsx | 4 ++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/preview-web/src/DocsRender.ts b/lib/preview-web/src/DocsRender.ts index d386611584e..6eabc49f909 100644 --- a/lib/preview-web/src/DocsRender.ts +++ b/lib/preview-web/src/DocsRender.ts @@ -72,12 +72,12 @@ export class DocsRender implements Render { expect(mockChannel.emit).toHaveBeenCalledWith(STORY_RENDERED, 'component-one--a'); }); - describe('in docs mode', () => { + describe('in docs mode, legacy inline render', () => { + it('re-renders the docs container', async () => { + document.location.search = '?id=component-one--a&viewMode=docs'; + + await createAndRenderPreview(); + + mockChannel.emit.mockClear(); + emitter.emit(UPDATE_GLOBALS, { globals: { foo: 'bar' } }); + await waitForRender(); + + expect(ReactDOM.render).toHaveBeenCalledTimes(2); + }); + }); + + describe('in docs mode, modern inline render', () => { + beforeEach(() => { + global.FEATURES.modernInlineRender = true; + }); + afterEach(() => { + global.FEATURES.modernInlineRender = false; + }); it('re-renders the docs container', async () => { document.location.search = '?id=component-one--a&viewMode=docs'; @@ -982,7 +1002,7 @@ describe('PreviewWeb', () => { global.FEATURES.modernInlineRender = true; }); afterEach(() => { - global.FEATURES.modernInlineRender = true; + global.FEATURES.modernInlineRender = false; }); it('does not re-render the docs container', async () => { document.location.search = '?id=component-one--a&viewMode=docs'; diff --git a/lib/preview-web/src/PreviewWeb.tsx b/lib/preview-web/src/PreviewWeb.tsx index 6c455bd2e93..891eb1dd533 100644 --- a/lib/preview-web/src/PreviewWeb.tsx +++ b/lib/preview-web/src/PreviewWeb.tsx @@ -212,7 +212,7 @@ export class PreviewWeb extends Preview extends Preview Date: Thu, 21 Jul 2022 17:26:35 +1000 Subject: [PATCH 3/5] Shouldn't have dropped this --- lib/store/package.json | 1 + yarn.lock | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/store/package.json b/lib/store/package.json index 30bcf177748..27c3da39b63 100644 --- a/lib/store/package.json +++ b/lib/store/package.json @@ -41,6 +41,7 @@ "prepare": "node ../../scripts/prepare.js" }, "dependencies": { + "@storybook/addons": "7.0.0-alpha.13", "@storybook/client-logger": "7.0.0-alpha.13", "@storybook/core-events": "7.0.0-alpha.13", "@storybook/csf": "0.0.2--canary.4566f4d.1", diff --git a/yarn.lock b/yarn.lock index b11eafc5117..5d78fde0bf9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9449,6 +9449,7 @@ __metadata: version: 0.0.0-use.local resolution: "@storybook/store@workspace:lib/store" dependencies: + "@storybook/addons": 7.0.0-alpha.13 "@storybook/client-logger": 7.0.0-alpha.13 "@storybook/core-events": 7.0.0-alpha.13 "@storybook/csf": 0.0.2--canary.4566f4d.1 From 72c3af4b20a5a33deeada736542e3719ac43186c Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 21 Jul 2022 09:44:29 +0200 Subject: [PATCH 4/5] update snapshots --- .../src/__snapshots__/cra-ts-essentials_preview-dev-posix | 7 +++++++ .../src/__snapshots__/cra-ts-essentials_preview-prod-posix | 7 +++++++ .../src/__snapshots__/html-kitchen-sink_preview-dev-posix | 7 +++++++ .../src/__snapshots__/html-kitchen-sink_preview-prod-posix | 7 +++++++ .../src/__snapshots__/vue-3-cli_preview-dev-posix | 7 +++++++ .../src/__snapshots__/vue-3-cli_preview-prod-posix | 7 +++++++ .../web-components-kitchen-sink_preview-dev-posix | 7 +++++++ .../web-components-kitchen-sink_preview-prod-posix | 7 +++++++ 8 files changed, 56 insertions(+) diff --git a/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-dev-posix b/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-dev-posix index ff93880ea87..43f38974c51 100644 --- a/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-dev-posix +++ b/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-dev-posix @@ -413,6 +413,13 @@ Object { }, Object { "loader": "NODE_MODULES/@storybook/mdx1-csf/loader.js", + "options": Object { + "remarkPlugins": Array [ + [Function], + [Function], + ], + "skipCsf": false, + }, }, ], }, diff --git a/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-prod-posix b/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-prod-posix index 55a6f41e481..eac8b7b13ff 100644 --- a/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-prod-posix +++ b/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-prod-posix @@ -430,6 +430,13 @@ Object { }, Object { "loader": "NODE_MODULES/@storybook/mdx1-csf/loader.js", + "options": Object { + "remarkPlugins": Array [ + [Function], + [Function], + ], + "skipCsf": false, + }, }, ], }, diff --git a/lib/core-server/src/__snapshots__/html-kitchen-sink_preview-dev-posix b/lib/core-server/src/__snapshots__/html-kitchen-sink_preview-dev-posix index f8012763c73..eed5be83655 100644 --- a/lib/core-server/src/__snapshots__/html-kitchen-sink_preview-dev-posix +++ b/lib/core-server/src/__snapshots__/html-kitchen-sink_preview-dev-posix @@ -97,6 +97,13 @@ Object { }, Object { "loader": "NODE_MODULES/@storybook/mdx1-csf/loader.js", + "options": Object { + "remarkPlugins": Array [ + [Function], + [Function], + ], + "skipCsf": false, + }, }, ], }, diff --git a/lib/core-server/src/__snapshots__/html-kitchen-sink_preview-prod-posix b/lib/core-server/src/__snapshots__/html-kitchen-sink_preview-prod-posix index 963e8650616..3e20431918f 100644 --- a/lib/core-server/src/__snapshots__/html-kitchen-sink_preview-prod-posix +++ b/lib/core-server/src/__snapshots__/html-kitchen-sink_preview-prod-posix @@ -96,6 +96,13 @@ Object { }, Object { "loader": "NODE_MODULES/@storybook/mdx1-csf/loader.js", + "options": Object { + "remarkPlugins": Array [ + [Function], + [Function], + ], + "skipCsf": false, + }, }, ], }, diff --git a/lib/core-server/src/__snapshots__/vue-3-cli_preview-dev-posix b/lib/core-server/src/__snapshots__/vue-3-cli_preview-dev-posix index 8be7356c9f4..f6c0aeb67e8 100644 --- a/lib/core-server/src/__snapshots__/vue-3-cli_preview-dev-posix +++ b/lib/core-server/src/__snapshots__/vue-3-cli_preview-dev-posix @@ -126,6 +126,13 @@ Object { }, Object { "loader": "NODE_MODULES/@storybook/mdx1-csf/loader.js", + "options": Object { + "remarkPlugins": Array [ + [Function], + [Function], + ], + "skipCsf": false, + }, }, ], }, diff --git a/lib/core-server/src/__snapshots__/vue-3-cli_preview-prod-posix b/lib/core-server/src/__snapshots__/vue-3-cli_preview-prod-posix index 2cd4cf1c2b6..765bbe0bb90 100644 --- a/lib/core-server/src/__snapshots__/vue-3-cli_preview-prod-posix +++ b/lib/core-server/src/__snapshots__/vue-3-cli_preview-prod-posix @@ -125,6 +125,13 @@ Object { }, Object { "loader": "NODE_MODULES/@storybook/mdx1-csf/loader.js", + "options": Object { + "remarkPlugins": Array [ + [Function], + [Function], + ], + "skipCsf": false, + }, }, ], }, diff --git a/lib/core-server/src/__snapshots__/web-components-kitchen-sink_preview-dev-posix b/lib/core-server/src/__snapshots__/web-components-kitchen-sink_preview-dev-posix index e7e98abcf95..5660c2060a3 100644 --- a/lib/core-server/src/__snapshots__/web-components-kitchen-sink_preview-dev-posix +++ b/lib/core-server/src/__snapshots__/web-components-kitchen-sink_preview-dev-posix @@ -133,6 +133,13 @@ Object { }, Object { "loader": "NODE_MODULES/@storybook/mdx1-csf/loader.js", + "options": Object { + "remarkPlugins": Array [ + [Function], + [Function], + ], + "skipCsf": false, + }, }, ], }, diff --git a/lib/core-server/src/__snapshots__/web-components-kitchen-sink_preview-prod-posix b/lib/core-server/src/__snapshots__/web-components-kitchen-sink_preview-prod-posix index e5ea7dbf7ad..9ded2d24ecb 100644 --- a/lib/core-server/src/__snapshots__/web-components-kitchen-sink_preview-prod-posix +++ b/lib/core-server/src/__snapshots__/web-components-kitchen-sink_preview-prod-posix @@ -132,6 +132,13 @@ Object { }, Object { "loader": "NODE_MODULES/@storybook/mdx1-csf/loader.js", + "options": Object { + "remarkPlugins": Array [ + [Function], + [Function], + ], + "skipCsf": false, + }, }, ], }, From aafc83a6a6a9d87be4980e1ae8f7911378bc7cdf Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 21 Jul 2022 09:51:39 +0200 Subject: [PATCH 5/5] fix deepscan --- scripts/dts-localize.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/dts-localize.ts b/scripts/dts-localize.ts index 61bd2159f07..f3184b38857 100644 --- a/scripts/dts-localize.ts +++ b/scripts/dts-localize.ts @@ -1,5 +1,5 @@ /* eslint-disable no-param-reassign */ -import path, { dirname, isAbsolute, join, resolve } from 'path'; +import path, { dirname, isAbsolute, join, relative, resolve, sep } from 'path'; import fs from 'fs-extra'; import { sync } from 'read-pkg-up'; import slash from 'slash'; @@ -47,7 +47,7 @@ function getCompilerOptions(inputFileNames: string[], preferredConfigPath?: stri const compilerOptionsParseResult = ts.parseJsonConfigFileContent( configParseResult.config, parseConfigHost, - path.resolve(path.dirname(configFileName)), + resolve(dirname(configFileName)), undefined, getAbsolutePath(configFileName) ); @@ -86,7 +86,7 @@ export const run = async (entrySourceFiles: string[], outputPath: string, option * @param {string} filePath the path of the current file */ function getReplacementPathRelativeToBase(basePath: string, filePath: string) { - const relative = path.relative(basePath, filePath); + const relativePath = relative(basePath, filePath); let newPath = ''; /* @@ -101,16 +101,16 @@ export const run = async (entrySourceFiles: string[], outputPath: string, option */ - if (relative.includes(`node_modules${path.sep}`)) { - const [, ...parts] = relative.split(`node_modules${path.sep}`); - const filename = parts.join(`node_modules${path.sep}`).split(path.sep).join('-'); + if (relativePath.includes(`node_modules${sep}`)) { + const [, ...parts] = relativePath.split(`node_modules${sep}`); + const filename = parts.join(`node_modules${sep}`).split(sep).join('-'); newPath = join(outputPath, '_modules', filename); - } else if (relative.includes(join('dist', `ts-tmp${path.sep}`))) { - const [, ...parts] = relative.split(join('dist', `ts-tmp${path.sep}`)); - const filename = parts.join('').split(path.sep).join('-'); + } else if (relativePath.includes(join('dist', `ts-tmp${sep}`))) { + const [, ...parts] = relativePath.split(join('dist', `ts-tmp${sep}`)); + const filename = parts.join('').split(sep).join('-'); newPath = join(outputPath, filename); } else { - const filename = relative.split(path.sep).join('-'); + const filename = relativePath.split(sep).join('-'); newPath = join(outputPath, filename); } return newPath;