diff --git a/MIGRATION.md b/MIGRATION.md index 99c1b5fdffc3..5a281143b736 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -53,6 +53,7 @@ - [Deprecated docs parameters](#deprecated-docs-parameters) - [Description Doc block properties](#description-doc-block-properties) - [Manager API expandAll and collapseAll methods](#manager-api-expandall-and-collapseall-methods) + - [`createChannel` from `@storybook/postmessage` and `@storybook/channel-websocket`](#createchannel-from-storybookpostmessage-and--storybookchannel-websocket) - [From version 7.5.0 to 7.6.0](#from-version-750-to-760) - [CommonJS with Vite is deprecated](#commonjs-with-vite-is-deprecated) - [Using implicit actions during rendering is deprecated](#using-implicit-actions-during-rendering-is-deprecated) @@ -877,6 +878,12 @@ api.collapseAll() // becomes api.emit(STORIES_COLLAPSE_ALL) api.expandAll() // becomes api.emit(STORIES_EXPAND_ALL) ``` +#### `createChannel` from `@storybook/postmessage` and `@storybook/channel-websocket` + +The `createChannel` APIs from both `@storybook/channel-websocket` and `@storybook/postmessage` are now removed. Please use `createBrowserChannel` instead, from the `@storybook/channels` package. + +Additionally, the `PostmsgTransport` type is now removed in favor of `PostMessageTransport`. + ## From version 7.5.0 to 7.6.0 #### CommonJS with Vite is deprecated diff --git a/code/lib/channels/src/index.ts b/code/lib/channels/src/index.ts index a6c975752f13..7942d57fa4f3 100644 --- a/code/lib/channels/src/index.ts +++ b/code/lib/channels/src/index.ts @@ -13,8 +13,8 @@ export * from './main'; export default Channel; -export { createChannel as createPostMessageChannel, PostMessageTransport } from './postmessage'; -export { createChannel as createWebSocketChannel, WebsocketTransport } from './websocket'; +export { PostMessageTransport } from './postmessage'; +export { WebsocketTransport } from './websocket'; type Options = Config & { extraTransports?: ChannelTransport[]; diff --git a/code/lib/channels/src/postmessage/index.ts b/code/lib/channels/src/postmessage/index.ts index a49997fc3d32..e1c7332121b6 100644 --- a/code/lib/channels/src/postmessage/index.ts +++ b/code/lib/channels/src/postmessage/index.ts @@ -7,7 +7,6 @@ import { logger, pretty } from '@storybook/client-logger'; import { isJSON, parse, stringify } from 'telejson'; import qs from 'qs'; import invariant from 'tiny-invariant'; -import { Channel } from '../main'; import type { ChannelTransport, BufferedEvent, @@ -243,25 +242,3 @@ export class PostMessageTransport implements ChannelTransport { } } } - -/** - * @deprecated This export is deprecated. Use `PostMessageTransport` instead. This API will be removed in 8.0. - */ -export const PostmsgTransport = PostMessageTransport; - -/** - * @deprecated This function is deprecated. Use the `createBrowserChannel` factory function from `@storybook/channels` instead. This API will be removed in 8.0. - * @param {Config} config - The configuration object. - * @returns {Channel} The channel instance. - */ -export function createChannel({ page }: Config): Channel { - const transport = new PostmsgTransport({ page }); - return new Channel({ transport }); -} - -/** - * @deprecated This function is deprecated. Use the `createBrowserChannel` factory function from `@storybook/channels` instead. This API will be removed in 8.0. - * @param {Config} config - The configuration object. - * @returns {Channel} The channel instance. - */ -export default createChannel; diff --git a/code/lib/channels/src/websocket/index.ts b/code/lib/channels/src/websocket/index.ts index c07a96ffd71e..b4530de965c9 100644 --- a/code/lib/channels/src/websocket/index.ts +++ b/code/lib/channels/src/websocket/index.ts @@ -2,10 +2,9 @@ /// import { global } from '@storybook/global'; -import { logger } from '@storybook/client-logger'; import { isJSON, parse, stringify } from 'telejson'; import invariant from 'tiny-invariant'; -import { Channel } from '../main'; + import type { ChannelTransport, ChannelHandler } from '../types'; const { WebSocket } = global; @@ -17,12 +16,6 @@ interface WebsocketTransportArgs { onError: OnError; } -interface CreateChannelArgs { - url?: string; - async?: boolean; - onError?: OnError; -} - export class WebsocketTransport implements ChannelTransport { private buffer: string[] = []; @@ -77,30 +70,3 @@ export class WebsocketTransport implements ChannelTransport { buffer.forEach((event) => this.send(event)); } } - -/** - * @deprecated This function is deprecated. Use the `createBrowserChannel` factory function from `@storybook/channels` instead. This API will be removed in 8.0. - * @param {CreateChannelArgs} options - The options for creating the channel. - * @param {string} [options.url] - The URL of the WebSocket server to connect to. - * @param {boolean} [options.async=false] - Whether the channel should be asynchronous. - * @param {OnError} [options.onError] - A function to handle errors that occur during the channel's lifetime. - * @returns {Channel} - The newly created channel. - */ -export function createChannel({ - url, - async = false, - onError = (err) => logger.warn(err), -}: CreateChannelArgs) { - let channelUrl = url; - if (!channelUrl) { - const protocol = window.location.protocol === 'http:' ? 'ws' : 'wss'; - const { hostname, port } = window.location; - channelUrl = `${protocol}://${hostname}:${port}/storybook-server-channel`; - } - - const transport = new WebsocketTransport({ url: channelUrl, onError }); - return new Channel({ transport, async }); -} - -// backwards compat with builder-vite -export default createChannel; diff --git a/code/ui/manager/src/globals/exports.ts b/code/ui/manager/src/globals/exports.ts index 1da23ad426dc..b8e2d5b14868 100644 --- a/code/ui/manager/src/globals/exports.ts +++ b/code/ui/manager/src/globals/exports.ts @@ -127,8 +127,6 @@ export default { 'PostMessageTransport', 'WebsocketTransport', 'createBrowserChannel', - 'createPostMessageChannel', - 'createWebSocketChannel', ], '@storybook/core-events': [ 'CHANNEL_CREATED',