Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only connect to serverChannel in development mode #22575

Merged
merged 3 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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