Skip to content

Commit

Permalink
Merge pull request #22575 from storybookjs/norbert/serverchannel-mana…
Browse files Browse the repository at this point in the history
…ger-fix

only connect to serverChannel in development mode
  • Loading branch information
ndelangen authored May 22, 2023
2 parents 7ed98c7 + ab278ef commit 28f8733
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion code/lib/builder-manager/src/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const renderHTML = async (
refs: Promise<Record<string, Ref>>,
logLevel: Promise<string>,
docsOptions: Promise<DocsOptions>,
{ versionCheck, releaseNotesData, previewUrl, serverChannelUrl, configType }: Options
{ versionCheck, releaseNotesData, previewUrl, configType }: Options
) => {
const customHeadRef = await customHead;
const titleRef = await title;
Expand Down
11 changes: 7 additions & 4 deletions code/lib/builder-vite/src/codegen-set-addon-channel.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
export async function generateAddonSetupCode() {
return `
import { global } from '@storybook/global';
import { createChannel as createPostMessageChannel } from '@storybook/channel-postmessage';
import { createChannel as createWebSocketChannel } from '@storybook/channel-websocket';
import { addons } from '@storybook/preview-api';
const channel = createPostMessageChannel({ page: 'preview' });
addons.setChannel(channel);
window.__STORYBOOK_ADDONS_CHANNEL__ = channel;
const serverChannel = createWebSocketChannel({});
addons.setServerChannel(serverChannel);
window.__STORYBOOK_SERVER_CHANNEL__ = serverChannel;
if (global.CONFIG_TYPE === 'DEVELOPMENT'){
const serverChannel = createWebSocketChannel({});
addons.setServerChannel(serverChannel);
window.__STORYBOOK_SERVER_CHANNEL__ = serverChannel;
}
`.trim();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ const getProjectAnnotations = () =>
const channel = createPostMessageChannel({ page: 'preview' });
addons.setChannel(channel);

const serverChannel = createWebSocketChannel({});
addons.setServerChannel(serverChannel);
window.__STORYBOOK_SERVER_CHANNEL__ = serverChannel;
if (global.CONFIG_TYPE === 'DEVELOPMENT'){
const serverChannel = createWebSocketChannel({});
addons.setServerChannel(serverChannel);
window.__STORYBOOK_SERVER_CHANNEL__ = serverChannel;
}

const preview = new PreviewWeb();

Expand Down
4 changes: 2 additions & 2 deletions code/ui/manager/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { renderStorybookUI } from './index';
import { values } from './globals/runtime';
import { Keys } from './globals/types';

const { FEATURES } = global;
const { FEATURES, CONFIG_TYPE } = global;

class ReactProvider extends Provider {
private addons: AddonStore;
Expand All @@ -35,7 +35,7 @@ class ReactProvider extends Provider {
this.addons = addons;
this.channel = postMessageChannel;

if (FEATURES?.storyStoreV7) {
if (FEATURES?.storyStoreV7 && CONFIG_TYPE === 'DEVELOPMENT') {
const serverChannel = webSocket.createChannel({});
this.serverChannel = serverChannel;
addons.setServerChannel(this.serverChannel);
Expand Down

0 comments on commit 28f8733

Please sign in to comment.