Skip to content

Commit 45ec15e

Browse files
authored
Merge pull request #1515 from storybooks/addon-channel-warning
Addon channel warning
2 parents afeebe0 + 983dd74 commit 45ec15e

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

app/react-native/src/preview/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,15 @@ export default class Preview {
5555
getStorybookUI(params = {}) {
5656
return () => {
5757
let webUrl = null;
58-
let channel = addons.getChannel();
58+
let channel = null;
59+
60+
try {
61+
channel = addons.getChannel();
62+
} catch (e) {
63+
// getChannel throws if the channel is not defined,
64+
// which is fine in this case (we will define it below)
65+
}
66+
5967
if (params.resetStorybook || !channel) {
6068
const host = params.host || parse(NativeModules.SourceCode.scriptURL).hostname;
6169
const port = params.port !== false ? `:${params.port || 7007}` : '';

lib/addons/src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ export class AddonStore {
22
constructor() {
33
this.loaders = {};
44
this.panels = {};
5-
// this.channel should get overwritten by setChannel if package versions are
6-
// correct and AddonStore is a proper singleton. If not, this will be null
7-
// (currently required by @storybook/react-native getStorybookUI)
85
this.channel = null;
96
this.preview = null;
107
this.database = null;
118
}
129

1310
getChannel() {
11+
// this.channel should get overwritten by setChannel if package versions are
12+
// correct and AddonStore is a proper singleton. If not, throw.
13+
if (!this.channel) {
14+
throw new Error(
15+
'Accessing nonexistent addons channel, see https://storybook.js.org/basics/faq/#why-is-there-no-addons-channel'
16+
);
17+
}
1418
return this.channel;
1519
}
1620

0 commit comments

Comments
 (0)