Skip to content

Commit 0f86613

Browse files
shilmanndelangen
authored andcommitted
Merge pull request #32287 from storybookjs/shilman/error-utm
Telemetry: Add ref=error/upgrade/ui to links (cherry picked from commit 14cf3d9)
1 parent 633478c commit 0f86613

29 files changed

Lines changed: 189 additions & 53 deletions

File tree

‎code/addons/docs/src/blocks/components/ArgsTable/ArgControl.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ export const ArgControl: FC<ArgControlProps> = ({ row, arg, updateArgs, isHovere
7272
if (!control || control.disable) {
7373
const canBeSetup = control?.disable !== true && row?.type?.name !== 'function';
7474
return isHovered && canBeSetup ? (
75-
<Link href="https://storybook.js.org/docs/essentials/controls" target="_blank" withArrow>
75+
<Link
76+
href="https://storybook.js.org/docs/essentials/controls?ref=ui"
77+
target="_blank"
78+
withArrow
79+
>
7680
Setup controls
7781
</Link>
7882
) : (

‎code/addons/docs/src/blocks/components/ArgsTable/ArgsTable.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export const ArgsTable: FC<ArgsTableProps> = (props) => {
331331
return (
332332
<EmptyBlock>
333333
{error}&nbsp;
334-
<Link href="http://storybook.js.org/docs/" target="_blank" withArrow>
334+
<Link href="http://storybook.js.org/docs/?ref=ui" target="_blank" withArrow>
335335
<DocumentIcon /> Read the docs
336336
</Link>
337337
</EmptyBlock>

‎code/addons/docs/src/blocks/components/ArgsTable/Empty.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const Empty: FC<EmptyProps> = ({ inAddonPanel }) => {
6767
{inAddonPanel && (
6868
<>
6969
<Link
70-
href="https://storybook.js.org/docs/essentials/controls"
70+
href="https://storybook.js.org/docs/essentials/controls?ref=ui"
7171
target="_blank"
7272
withArrow
7373
>
@@ -77,7 +77,7 @@ export const Empty: FC<EmptyProps> = ({ inAddonPanel }) => {
7777
)}
7878
{!inAddonPanel && (
7979
<Link
80-
href="https://storybook.js.org/docs/essentials/controls"
80+
href="https://storybook.js.org/docs/essentials/controls?ref=ui"
8181
target="_blank"
8282
withArrow
8383
>

‎code/addons/docs/src/blocks/components/Story.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ const Story: FunctionComponent<StoryProps> = (props) => {
126126
return (
127127
<ErrorMessage>
128128
This story mounts inside of play. Set{' '}
129-
<a href="https://storybook.js.org/docs/api/doc-blocks/doc-block-story#autoplay">autoplay</a>{' '}
129+
<a href="https://storybook.js.org/docs/api/doc-blocks/doc-block-story?ref=ui#autoplay">
130+
autoplay
131+
</a>{' '}
130132
to true to view this story.
131133
</ErrorMessage>
132134
);

‎code/addons/vitest/src/preset.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const experimental_serverChannel = async (channel: Channel, options: Opti
6565
log(dedent`
6666
You're using ${framework}, which is a Webpack-based builder. In order to use Storybook Test, with your project, you need to use '@storybook/nextjs-vite', a high performance Vite-based equivalent.
6767
68-
Information on how to upgrade here: ${picocolors.yellow('https://storybook.js.org/docs/get-started/frameworks/nextjs#with-vite')}\n
68+
Information on how to upgrade here: ${picocolors.yellow('https://storybook.js.org/docs/get-started/frameworks/nextjs?ref=upgrade#with-vite')}\n
6969
`);
7070
}
7171
return channel;

‎code/core/src/__tests/storybook-error.test.ts‎

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest';
22

3-
import { StorybookError } from '../storybook-error';
3+
import { StorybookError, appendErrorRef } from '../storybook-error';
44

55
describe('StorybookError', () => {
66
class TestError extends StorybookError {
@@ -28,7 +28,7 @@ describe('StorybookError', () => {
2828
it('should generate the correct message with internal documentation link', () => {
2929
const error = new TestError(true);
3030
const expectedMessage =
31-
'This is a test error.\n\nMore info: https://storybook.js.org/error/SB_TEST_CATEGORY_0123\n';
31+
'This is a test error.\n\nMore info: https://storybook.js.org/error/SB_TEST_CATEGORY_0123?ref=error\n';
3232
expect(error.message).toBe(expectedMessage);
3333
});
3434

@@ -45,14 +45,14 @@ describe('StorybookError', () => {
4545
it('should generate the correct message with multiple external documentation links', () => {
4646
const error = new TestError([
4747
'https://example.com/docs/first-error',
48-
'https://example.com/docs/second-error',
48+
'https://storybook.js.org/docs/second-error',
4949
]);
5050
expect(error.message).toMatchInlineSnapshot(`
5151
"This is a test error.
5252
5353
More info:
5454
- https://example.com/docs/first-error
55-
- https://example.com/docs/second-error
55+
- https://storybook.js.org/docs/second-error?ref=error
5656
"
5757
`);
5858
});
@@ -62,3 +62,83 @@ describe('StorybookError', () => {
6262
expect(error.documentation).toBe(false);
6363
});
6464
});
65+
66+
describe('appendErrorRef', () => {
67+
it('should append ref=error to storybook.js.org URLs without query parameters', () => {
68+
const url = 'https://storybook.js.org/docs/example';
69+
const result = appendErrorRef(url);
70+
expect(result).toBe('https://storybook.js.org/docs/example?ref=error');
71+
});
72+
73+
it('should append ref=error to storybook.js.org URLs with existing query parameters', () => {
74+
const url = 'https://storybook.js.org/docs/example?foo=bar';
75+
const result = appendErrorRef(url);
76+
expect(result).toBe('https://storybook.js.org/docs/example?foo=bar&ref=error');
77+
});
78+
79+
it('should append ref=error to storybook.js.org URLs with multiple existing query parameters', () => {
80+
const url = 'https://storybook.js.org/docs/example?foo=bar&baz=qux';
81+
const result = appendErrorRef(url);
82+
expect(result).toBe('https://storybook.js.org/docs/example?foo=bar&baz=qux&ref=error');
83+
});
84+
85+
it('should handle storybook.js.org URLs with hash fragments', () => {
86+
const url = 'https://storybook.js.org/docs/example#section';
87+
const result = appendErrorRef(url);
88+
expect(result).toBe('https://storybook.js.org/docs/example?ref=error#section');
89+
});
90+
91+
it('should handle storybook.js.org URLs with query parameters and hash fragments', () => {
92+
const url = 'https://storybook.js.org/docs/example?foo=bar#section';
93+
const result = appendErrorRef(url);
94+
expect(result).toBe('https://storybook.js.org/docs/example?foo=bar&ref=error#section');
95+
});
96+
97+
it('should not modify non-storybook.js.org URLs', () => {
98+
const url = 'https://example.com/docs/test-error';
99+
const result = appendErrorRef(url);
100+
expect(result).toBe('https://example.com/docs/test-error');
101+
});
102+
103+
it('should not modify relative URLs', () => {
104+
const url = '/docs/example';
105+
const result = appendErrorRef(url);
106+
expect(result).toBe('/docs/example');
107+
});
108+
109+
it('should not modify empty string URLs', () => {
110+
const url = '';
111+
const result = appendErrorRef(url);
112+
expect(result).toBe('');
113+
});
114+
115+
it('should not modify other domain URLs', () => {
116+
const url = 'https://github.com/storybookjs/storybook/issues/123';
117+
const result = appendErrorRef(url);
118+
expect(result).toBe('https://github.com/storybookjs/storybook/issues/123');
119+
});
120+
121+
it('should not append ref=error if it already exists in the URL', () => {
122+
const url = 'https://storybook.js.org/docs/example?ref=error';
123+
const result = appendErrorRef(url);
124+
expect(result).toBe('https://storybook.js.org/docs/example?ref=error');
125+
});
126+
127+
it('should not append ref=error if it already exists with other parameters', () => {
128+
const url = 'https://storybook.js.org/docs/example?foo=bar&ref=error&baz=qux';
129+
const result = appendErrorRef(url);
130+
expect(result).toBe('https://storybook.js.org/docs/example?foo=bar&ref=error&baz=qux');
131+
});
132+
133+
it('should not append ref=error if it already exists in URL with hash fragment', () => {
134+
const url = 'https://storybook.js.org/docs/example?ref=error#target';
135+
const result = appendErrorRef(url);
136+
expect(result).toBe('https://storybook.js.org/docs/example?ref=error#target');
137+
});
138+
139+
it('should append ref=error before hash fragment when no existing ref parameter', () => {
140+
const url = 'https://storybook.js.org/docs/example#target';
141+
const result = appendErrorRef(url);
142+
expect(result).toBe('https://storybook.js.org/docs/example?ref=error#target');
143+
});
144+
});

‎code/core/src/core-server/utils/StoryIndexGenerator.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ export class StoryIndexGenerator {
593593
if (err && (err as { source: any }).source?.match(/mdast-util-mdx-jsx/g)) {
594594
logger.warn(
595595
`💡 This seems to be an MDX2 syntax error. Please refer to the MDX section in the following resource for assistance on how to fix this: ${picocolors.yellow(
596-
'https://storybook.js.org/migration-guides/7.0'
596+
'https://storybook.js.org/docs/7/migration-guide?ref=error'
597597
)}`
598598
);
599599
}

‎code/core/src/core-server/utils/__tests__/remove-mdx-stories.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Your main configuration somehow does not contain a 'stories' field, or it resolv
5656
5757
Please check your main configuration file and make sure it exports a 'stories' field that is not an empty array.
5858
59-
More info: https://storybook.js.org/docs/faq#can-i-have-a-storybook-with-no-local-stories
59+
More info: https://storybook.js.org/docs/faq?ref=error#can-i-have-a-storybook-with-no-local-stories
6060
]
6161
`);
6262
});

‎code/core/src/csf-tools/CsfFile.test.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,7 @@ describe('CsfFile', () => {
25132513
).toThrowErrorMatchingInlineSnapshot(`
25142514
[MultipleMetaError: CSF: multiple meta objects (line 4, col 24)
25152515
2516-
More info: https://storybook.js.org/docs/writing-stories#default-export]
2516+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
25172517
`);
25182518
});
25192519

@@ -2531,7 +2531,7 @@ describe('CsfFile', () => {
25312531
).toThrowErrorMatchingInlineSnapshot(`
25322532
[MultipleMetaError: CSF: multiple meta objects (line 3, col 25)
25332533
2534-
More info: https://storybook.js.org/docs/writing-stories#default-export]
2534+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
25352535
`);
25362536
});
25372537

@@ -2549,7 +2549,7 @@ describe('CsfFile', () => {
25492549
).toThrowErrorMatchingInlineSnapshot(`
25502550
[MultipleMetaError: CSF: multiple meta objects
25512551
2552-
More info: https://storybook.js.org/docs/writing-stories#default-export]
2552+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
25532553
`);
25542554
});
25552555

@@ -2565,7 +2565,7 @@ describe('CsfFile', () => {
25652565
).toThrowErrorMatchingInlineSnapshot(`
25662566
[BadMetaError: CSF: meta() factory must be imported from .storybook/preview configuration (line 1, col 0)
25672567
2568-
More info: https://storybook.js.org/docs/writing-stories#default-export]
2568+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
25692569
`);
25702570
});
25712571

@@ -2582,7 +2582,7 @@ describe('CsfFile', () => {
25822582
).toThrowErrorMatchingInlineSnapshot(`
25832583
[BadMetaError: CSF: meta() factory must be imported from .storybook/preview configuration (line 4, col 28)
25842584
2585-
More info: https://storybook.js.org/docs/writing-stories#default-export]
2585+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
25862586
`);
25872587
});
25882588

@@ -2599,7 +2599,7 @@ describe('CsfFile', () => {
25992599
).toThrowErrorMatchingInlineSnapshot(`
26002600
[MixedFactoryError: CSF: expected factory story (line 4, col 17)
26012601
2602-
More info: https://storybook.js.org/docs/writing-stories#default-export]
2602+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
26032603
`);
26042604
});
26052605

@@ -2616,7 +2616,7 @@ describe('CsfFile', () => {
26162616
).toThrowErrorMatchingInlineSnapshot(`
26172617
[MixedFactoryError: CSF: expected non-factory story (line 4, col 28)
26182618
2619-
More info: https://storybook.js.org/docs/writing-stories#default-export]
2619+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error]
26202620
`);
26212621
});
26222622
});

‎code/core/src/csf-tools/CsfFile.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class NoMetaError extends Error {
181181
super(dedent`
182182
CSF: ${msg} ${formatLocation(ast, fileName)}
183183
184-
More info: https://storybook.js.org/docs/writing-stories#default-export
184+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error
185185
`);
186186
this.name = this.constructor.name;
187187
}
@@ -193,7 +193,7 @@ export class MultipleMetaError extends Error {
193193
super(dedent`
194194
CSF: ${message} ${formatLocation(ast, fileName)}
195195
196-
More info: https://storybook.js.org/docs/writing-stories#default-export
196+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error
197197
`);
198198
this.name = this.constructor.name;
199199
}
@@ -205,7 +205,7 @@ export class MixedFactoryError extends Error {
205205
super(dedent`
206206
CSF: ${message} ${formatLocation(ast, fileName)}
207207
208-
More info: https://storybook.js.org/docs/writing-stories#default-export
208+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error
209209
`);
210210
this.name = this.constructor.name;
211211
}
@@ -217,7 +217,7 @@ export class BadMetaError extends Error {
217217
super(dedent`
218218
CSF: ${message} ${formatLocation(ast, fileName)}
219219
220-
More info: https://storybook.js.org/docs/writing-stories#default-export
220+
More info: https://storybook.js.org/docs/writing-stories#default-export?ref=error
221221
`);
222222
this.name = this.constructor.name;
223223
}

0 commit comments

Comments
 (0)