Skip to content

Commit 0ba40c5

Browse files
Merge pull request #25487 from storybookjs/yann/remove-deprecated-create-channel-postmessage
Core: Remove deprecated createChannel APIs
2 parents 4dc764f + 4583800 commit 0ba40c5

File tree

5 files changed

+10
-62
lines changed

5 files changed

+10
-62
lines changed

MIGRATION.md

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
- [Deprecated docs parameters](#deprecated-docs-parameters)
5454
- [Description Doc block properties](#description-doc-block-properties)
5555
- [Manager API expandAll and collapseAll methods](#manager-api-expandall-and-collapseall-methods)
56+
- [`createChannel` from `@storybook/postmessage` and `@storybook/channel-websocket`](#createchannel-from-storybookpostmessage-and--storybookchannel-websocket)
5657
- [From version 7.5.0 to 7.6.0](#from-version-750-to-760)
5758
- [CommonJS with Vite is deprecated](#commonjs-with-vite-is-deprecated)
5859
- [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)
877878
api.expandAll() // becomes api.emit(STORIES_EXPAND_ALL)
878879
```
879880

881+
#### `createChannel` from `@storybook/postmessage` and `@storybook/channel-websocket`
882+
883+
The `createChannel` APIs from both `@storybook/channel-websocket` and `@storybook/postmessage` are now removed. Please use `createBrowserChannel` instead, from the `@storybook/channels` package.
884+
885+
Additionally, the `PostmsgTransport` type is now removed in favor of `PostMessageTransport`.
886+
880887
## From version 7.5.0 to 7.6.0
881888

882889
#### CommonJS with Vite is deprecated

code/lib/channels/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export * from './main';
1313

1414
export default Channel;
1515

16-
export { createChannel as createPostMessageChannel, PostMessageTransport } from './postmessage';
17-
export { createChannel as createWebSocketChannel, WebsocketTransport } from './websocket';
16+
export { PostMessageTransport } from './postmessage';
17+
export { WebsocketTransport } from './websocket';
1818

1919
type Options = Config & {
2020
extraTransports?: ChannelTransport[];

code/lib/channels/src/postmessage/index.ts

-23
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { logger, pretty } from '@storybook/client-logger';
77
import { isJSON, parse, stringify } from 'telejson';
88
import qs from 'qs';
99
import invariant from 'tiny-invariant';
10-
import { Channel } from '../main';
1110
import type {
1211
ChannelTransport,
1312
BufferedEvent,
@@ -243,25 +242,3 @@ export class PostMessageTransport implements ChannelTransport {
243242
}
244243
}
245244
}
246-
247-
/**
248-
* @deprecated This export is deprecated. Use `PostMessageTransport` instead. This API will be removed in 8.0.
249-
*/
250-
export const PostmsgTransport = PostMessageTransport;
251-
252-
/**
253-
* @deprecated This function is deprecated. Use the `createBrowserChannel` factory function from `@storybook/channels` instead. This API will be removed in 8.0.
254-
* @param {Config} config - The configuration object.
255-
* @returns {Channel} The channel instance.
256-
*/
257-
export function createChannel({ page }: Config): Channel {
258-
const transport = new PostmsgTransport({ page });
259-
return new Channel({ transport });
260-
}
261-
262-
/**
263-
* @deprecated This function is deprecated. Use the `createBrowserChannel` factory function from `@storybook/channels` instead. This API will be removed in 8.0.
264-
* @param {Config} config - The configuration object.
265-
* @returns {Channel} The channel instance.
266-
*/
267-
export default createChannel;

code/lib/channels/src/websocket/index.ts

+1-35
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
/// <reference path="../typings.d.ts" />
33

44
import { global } from '@storybook/global';
5-
import { logger } from '@storybook/client-logger';
65
import { isJSON, parse, stringify } from 'telejson';
76
import invariant from 'tiny-invariant';
8-
import { Channel } from '../main';
7+
98
import type { ChannelTransport, ChannelHandler } from '../types';
109

1110
const { WebSocket } = global;
@@ -17,12 +16,6 @@ interface WebsocketTransportArgs {
1716
onError: OnError;
1817
}
1918

20-
interface CreateChannelArgs {
21-
url?: string;
22-
async?: boolean;
23-
onError?: OnError;
24-
}
25-
2619
export class WebsocketTransport implements ChannelTransport {
2720
private buffer: string[] = [];
2821

@@ -77,30 +70,3 @@ export class WebsocketTransport implements ChannelTransport {
7770
buffer.forEach((event) => this.send(event));
7871
}
7972
}
80-
81-
/**
82-
* @deprecated This function is deprecated. Use the `createBrowserChannel` factory function from `@storybook/channels` instead. This API will be removed in 8.0.
83-
* @param {CreateChannelArgs} options - The options for creating the channel.
84-
* @param {string} [options.url] - The URL of the WebSocket server to connect to.
85-
* @param {boolean} [options.async=false] - Whether the channel should be asynchronous.
86-
* @param {OnError} [options.onError] - A function to handle errors that occur during the channel's lifetime.
87-
* @returns {Channel} - The newly created channel.
88-
*/
89-
export function createChannel({
90-
url,
91-
async = false,
92-
onError = (err) => logger.warn(err),
93-
}: CreateChannelArgs) {
94-
let channelUrl = url;
95-
if (!channelUrl) {
96-
const protocol = window.location.protocol === 'http:' ? 'ws' : 'wss';
97-
const { hostname, port } = window.location;
98-
channelUrl = `${protocol}://${hostname}:${port}/storybook-server-channel`;
99-
}
100-
101-
const transport = new WebsocketTransport({ url: channelUrl, onError });
102-
return new Channel({ transport, async });
103-
}
104-
105-
// backwards compat with builder-vite
106-
export default createChannel;

code/ui/manager/src/globals/exports.ts

-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ export default {
127127
'PostMessageTransport',
128128
'WebsocketTransport',
129129
'createBrowserChannel',
130-
'createPostMessageChannel',
131-
'createWebSocketChannel',
132130
],
133131
'@storybook/core-events': [
134132
'CHANNEL_CREATED',

0 commit comments

Comments
 (0)