Skip to content

Commit 3e908ff

Browse files
authored
Merge pull request #14 from storybookjs/7.0-remove-addContext
Remove uses of `AddContext`
2 parents d607151 + 04ffbe8 commit 3e908ff

File tree

3 files changed

+6
-86
lines changed

3 files changed

+6
-86
lines changed

src/mdx2.test.ts

+5-81
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ describe('mdx2', () => {
4242
foo.parameters = { storySource: { source: '"bar"' } };
4343
4444
const componentMeta = { title: 'foobar', includeStories: ['foo'] };
45-
46-
const mdxStoryNameToKey = { foo: 'foo' };
4745
`);
4846
});
4947

@@ -60,7 +58,6 @@ describe('mdx2', () => {
6058
// @ts-ignore
6159
expect(compileSync(input)).toMatchInlineSnapshot(`
6260
/*@jsxRuntime automatic @jsxImportSource react*/
63-
import { assertIsFn, AddContext } from "@storybook/addon-docs";
6461
import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
6562
function MDXContent(props = {}) {
6663
const {wrapper: MDXLayout} = props.components || ({});
@@ -100,12 +97,10 @@ describe('mdx2', () => {
10097
10198
const componentMeta = { title: 'foobar', includeStories: ["foo"], };
10299
103-
const mdxStoryNameToKey = {"foo":"foo"};
104-
105100
componentMeta.parameters = componentMeta.parameters || {};
106101
componentMeta.parameters.docs = {
107102
...(componentMeta.parameters.docs || {}),
108-
page: () => <AddContext mdxStoryNameToKey={mdxStoryNameToKey} mdxComponentAnnotations={componentMeta}><MDXContent /></AddContext>,
103+
page: () => <MDXContent />,
109104
};
110105
111106
export default componentMeta;
@@ -119,11 +114,7 @@ describe('mdx2', () => {
119114
120115
{3 + 3}
121116
`)
122-
).toMatchInlineSnapshot(`
123-
const componentMeta = { includeStories: [] };
124-
125-
const mdxStoryNameToKey = {};
126-
`);
117+
).toMatchInlineSnapshot(`const componentMeta = { includeStories: [] };`);
127118
});
128119
});
129120

@@ -163,8 +154,6 @@ describe('docs-mdx-compiler-plugin', () => {
163154
},
164155
includeStories: ['componentNotes'],
165156
};
166-
167-
const mdxStoryNameToKey = { 'component notes': 'componentNotes' };
168157
`);
169158
});
170159

@@ -191,8 +180,6 @@ describe('docs-mdx-compiler-plugin', () => {
191180
component: Button,
192181
includeStories: ['componentNotes'],
193182
};
194-
195-
const mdxStoryNameToKey = { 'component notes': 'componentNotes' };
196183
`);
197184
});
198185

@@ -225,8 +212,6 @@ describe('docs-mdx-compiler-plugin', () => {
225212
_Foo_.storyName = 'renamed';
226213
227214
const componentMeta = { title: 'MDX/CSF imports', includeStories: ['_Basic_', '_Other_', '_Foo_'] };
228-
229-
const mdxStoryNameToKey = { _Basic_: '_Basic_', _Other_: '_Other_', renamed: '_Foo_' };
230215
`);
231216
});
232217

@@ -268,8 +253,6 @@ describe('docs-mdx-compiler-plugin', () => {
268253
],
269254
includeStories: ['one'],
270255
};
271-
272-
const mdxStoryNameToKey = { one: 'one' };
273256
`);
274257
});
275258

@@ -292,8 +275,6 @@ describe('docs-mdx-compiler-plugin', () => {
292275
__page.parameters = { docsOnly: true };
293276
294277
const componentMeta = { title: 'docs-only', includeStories: ['__page'] };
295-
296-
const mdxStoryNameToKey = {};
297278
`);
298279
});
299280

@@ -330,8 +311,6 @@ describe('docs-mdx-compiler-plugin', () => {
330311
],
331312
includeStories: ['one'],
332313
};
333-
334-
const mdxStoryNameToKey = { one: 'one' };
335314
`);
336315
});
337316

@@ -350,8 +329,6 @@ describe('docs-mdx-compiler-plugin', () => {
350329
__page.parameters = { docsOnly: true };
351330
352331
const componentMeta = { title: "Addons/Docs/what's in a title?", includeStories: ['__page'] };
353-
354-
const mdxStoryNameToKey = {};
355332
`);
356333
});
357334

@@ -385,8 +362,6 @@ describe('docs-mdx-compiler-plugin', () => {
385362
helloStory.parameters = { storySource: { source: '<Button>{"Hello button"}</Button>' } };
386363
387364
const componentMeta = { title: 'Button', includeStories: ['one', 'helloStory'] };
388-
389-
const mdxStoryNameToKey = { one: 'one', 'hello story': 'helloStory' };
390365
`);
391366
});
392367

@@ -428,8 +403,6 @@ describe('docs-mdx-compiler-plugin', () => {
428403
component: Button,
429404
includeStories: ['componentNotes', 'storyNotes'],
430405
};
431-
432-
const mdxStoryNameToKey = { 'component notes': 'componentNotes', 'story notes': 'storyNotes' };
433406
`);
434407
});
435408

@@ -479,8 +452,6 @@ describe('docs-mdx-compiler-plugin', () => {
479452
component: Button,
480453
includeStories: ['helloButton', 'two'],
481454
};
482-
483-
const mdxStoryNameToKey = { 'hello button': 'helloButton', two: 'two' };
484455
`);
485456
});
486457

@@ -522,8 +493,6 @@ describe('docs-mdx-compiler-plugin', () => {
522493
componentNotes.parameters = { storySource: { source: 'args => <Button>Component notes</Button>' } };
523494
524495
const componentMeta = { title: 'Button', includeStories: ['componentNotes'] };
525-
526-
const mdxStoryNameToKey = { 'component notes': 'componentNotes' };
527496
`);
528497
});
529498

@@ -536,11 +505,7 @@ describe('docs-mdx-compiler-plugin', () => {
536505
537506
<Story id="." />
538507
`)
539-
).toMatchInlineSnapshot(`
540-
const componentMeta = { includeStories: [] };
541-
542-
const mdxStoryNameToKey = {};
543-
`);
508+
).toMatchInlineSnapshot(`const componentMeta = { includeStories: [] };`);
544509
});
545510

546511
it('story-def-text-only.mdx', () => {
@@ -560,8 +525,6 @@ describe('docs-mdx-compiler-plugin', () => {
560525
text.parameters = { storySource: { source: '"Plain text"' } };
561526
562527
const componentMeta = { title: 'Text', includeStories: ['text'] };
563-
564-
const mdxStoryNameToKey = { text: 'text' };
565528
`);
566529
});
567530

@@ -612,13 +575,6 @@ describe('docs-mdx-compiler-plugin', () => {
612575
title: 'Button',
613576
includeStories: ['one', 'helloStory', 'wPunctuation', '_1FineDay'],
614577
};
615-
616-
const mdxStoryNameToKey = {
617-
one: 'one',
618-
'hello story': 'helloStory',
619-
'w/punctuation': 'wPunctuation',
620-
'1 fine day': '_1FineDay',
621-
};
622578
`);
623579
});
624580

@@ -643,8 +599,6 @@ describe('docs-mdx-compiler-plugin', () => {
643599
basic.parameters = { storySource: { source: 'basicFn' } };
644600
645601
const componentMeta = { title: 'story-function-var', includeStories: ['basic'] };
646-
647-
const mdxStoryNameToKey = { basic: 'basic' };
648602
`);
649603
});
650604

@@ -676,8 +630,6 @@ describe('docs-mdx-compiler-plugin', () => {
676630
};
677631
678632
const componentMeta = { includeStories: ['functionStory'] };
679-
680-
const mdxStoryNameToKey = { function: 'functionStory' };
681633
`);
682634
});
683635

@@ -709,8 +661,6 @@ describe('docs-mdx-compiler-plugin', () => {
709661
};
710662
711663
const componentMeta = { title: 'Multiple', includeStories: ['multipleChildren'] };
712-
713-
const mdxStoryNameToKey = { 'multiple children': 'multipleChildren' };
714664
`);
715665
});
716666

@@ -756,8 +706,6 @@ describe('docs-mdx-compiler-plugin', () => {
756706
};
757707
758708
const componentMeta = { title: 'MDX|Welcome', includeStories: ['toStorybook'] };
759-
760-
const mdxStoryNameToKey = { 'to storybook': 'toStorybook' };
761709
`);
762710
});
763711

@@ -770,11 +718,7 @@ describe('docs-mdx-compiler-plugin', () => {
770718
771719
<Story id="welcome--welcome" />
772720
`)
773-
).toMatchInlineSnapshot(`
774-
const componentMeta = { includeStories: [] };
775-
776-
const mdxStoryNameToKey = {};
777-
`);
721+
).toMatchInlineSnapshot(`const componentMeta = { includeStories: [] };`);
778722
});
779723

780724
it('title-template-string.mdx', () => {
@@ -796,8 +740,6 @@ describe('docs-mdx-compiler-plugin', () => {
796740
__page.parameters = { docsOnly: true };
797741
798742
const componentMeta = { title: \`\${titleFunction('template')}\`, includeStories: ['__page'] };
799-
800-
const mdxStoryNameToKey = {};
801743
`);
802744
});
803745

@@ -812,11 +754,7 @@ describe('docs-mdx-compiler-plugin', () => {
812754
813755
<Button>Hello button</Button>
814756
`)
815-
).toMatchInlineSnapshot(`
816-
const componentMeta = { includeStories: [] };
817-
818-
const mdxStoryNameToKey = {};
819-
`);
757+
).toMatchInlineSnapshot(`const componentMeta = { includeStories: [] };`);
820758
});
821759

822760
it('errors on missing story props', async () => {
@@ -856,8 +794,6 @@ describe('docs-mdx-compiler-plugin', () => {
856794
__page.parameters = { docsOnly: true };
857795
858796
const componentMeta = { includeStories: ['__page'] };
859-
860-
const mdxStoryNameToKey = {};
861797
`);
862798
});
863799

@@ -879,8 +815,6 @@ describe('docs-mdx-compiler-plugin', () => {
879815
basic.parameters = { storySource: { source: '<Button>{"Basic"}</Button>' } };
880816
881817
const componentMeta = { component: Button, includeStories: ['basic'] };
882-
883-
const mdxStoryNameToKey = { Basic: 'basic' };
884818
`);
885819
});
886820

@@ -900,8 +834,6 @@ describe('docs-mdx-compiler-plugin', () => {
900834
basic.parameters = { storySource: { source: '{}' } };
901835
902836
const componentMeta = { title: 'Button', component: Button, includeStories: ['basic'] };
903-
904-
const mdxStoryNameToKey = { Basic: 'basic' };
905837
`);
906838
});
907839

@@ -926,8 +858,6 @@ describe('docs-mdx-compiler-plugin', () => {
926858
render: (args) => <Button {...args} />,
927859
includeStories: ['basic'],
928860
};
929-
930-
const mdxStoryNameToKey = { Basic: 'basic' };
931861
`);
932862
});
933863

@@ -948,8 +878,6 @@ describe('docs-mdx-compiler-plugin', () => {
948878
basic.render = (args) => <Button {...args} />;
949879
950880
const componentMeta = { title: 'Button', component: Button, includeStories: ['basic'] };
951-
952-
const mdxStoryNameToKey = { Basic: 'basic' };
953881
`);
954882
});
955883

@@ -970,8 +898,6 @@ describe('docs-mdx-compiler-plugin', () => {
970898
basic.play = () => console.log('play');
971899
972900
const componentMeta = { title: 'Button', component: Button, includeStories: ['basic'] };
973-
974-
const mdxStoryNameToKey = { Basic: 'basic' };
975901
`);
976902
});
977903
});
@@ -1011,8 +937,6 @@ describe('docs-mdx-compiler-plugin', () => {
1011937
__page.parameters = { docsOnly: true };
1012938
1013939
const componentMeta = { title: 'Example/Introduction', includeStories: ['__page'] };
1014-
1015-
const mdxStoryNameToKey = {};
1016940
`);
1017941
});
1018942
});

src/mdx2.ts

-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ function extractExports(root: t.File, options: CompilerOptions) {
9595
const fullJsx = [
9696
...storyExports,
9797
`const componentMeta = ${stringifyMeta(metaExport)};`,
98-
`const mdxStoryNameToKey = ${JSON.stringify(context.storyNameToKey)};`,
9998
wrapperJs,
10099
'export default componentMeta;',
101100
].join('\n\n');
@@ -121,7 +120,6 @@ export const postprocess = (code: string, extractedExports: string) => {
121120

122121
return [
123122
first,
124-
'import { assertIsFn, AddContext } from "@storybook/addon-docs";',
125123
...lines.filter((line) => !line.match(/^export default/)),
126124
SEPARATOR,
127125
extractedExports,

src/sb-mdx-plugin.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,11 @@ export function genMeta(ast: t.JSXElement, options: CompilerOptions) {
314314
};
315315
}
316316

317-
// insert `mdxStoryNameToKey` and `mdxComponentMeta` into the context so that we
318-
// can reconstruct the Story ID dynamically from the `name` at render time
319317
export const wrapperJs = `
320318
componentMeta.parameters = componentMeta.parameters || {};
321319
componentMeta.parameters.docs = {
322320
...(componentMeta.parameters.docs || {}),
323-
page: () => <AddContext mdxStoryNameToKey={mdxStoryNameToKey} mdxComponentAnnotations={componentMeta}><MDXContent /></AddContext>,
321+
page: () => <MDXContent />,
324322
};
325323
`.trim();
326324

0 commit comments

Comments
 (0)