diff --git a/lib/channel-websocket/package.json b/lib/channel-websocket/package.json index cdd523874684..4647fbaa77cb 100644 --- a/lib/channel-websocket/package.json +++ b/lib/channel-websocket/package.json @@ -31,7 +31,7 @@ "@storybook/channels": "5.3.13", "core-js": "^3.0.1", "global": "^4.3.2", - "json-fn": "^1.1.1" + "telejson": "^3.2.0" }, "publishConfig": { "access": "public" diff --git a/lib/channel-websocket/src/index.ts b/lib/channel-websocket/src/index.ts index d82f04081bce..53fb50ba6c17 100644 --- a/lib/channel-websocket/src/index.ts +++ b/lib/channel-websocket/src/index.ts @@ -1,6 +1,6 @@ import { WebSocket } from 'global'; -import JSON from 'json-fn'; import { Channel, ChannelHandler } from '@storybook/channels'; +import { isJSON, parse, stringify } from 'telejson'; type OnError = (message: Event) => void; @@ -45,7 +45,7 @@ export class WebsocketTransport { } private sendNow(event: any) { - const data = JSON.stringify(event); + const data = stringify(event, { maxDepth: 15, allowFunction: true }); this.socket.send(data); } @@ -61,8 +61,8 @@ export class WebsocketTransport { this.isReady = true; this.flush(); }; - this.socket.onmessage = e => { - const event = JSON.parse(e.data); + this.socket.onmessage = ({ data }) => { + const event = typeof data === 'string' && isJSON(data) ? parse(data) : data; this.handler(event); }; this.socket.onerror = e => { diff --git a/yarn.lock b/yarn.lock index 1baa60389788..ba2c6861d76f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19828,11 +19828,6 @@ json-buffer@3.0.0: resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.0.tgz#5b1f397afc75d677bde8bcfc0e47e1f9a3d9a898" integrity sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg= -json-fn@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/json-fn/-/json-fn-1.1.1.tgz#4293c9198a482d6697d334a6e32cd0d221121e80" - integrity sha1-QpPJGYpILWaX0zSm4yzQ0iESHoA= - json-parse-better-errors@^1.0.0, json-parse-better-errors@^1.0.1, json-parse-better-errors@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"