From 6d2fa3aa643fb056109f45cf98c6cc4bdabc62bf Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Fri, 3 Jul 2020 13:36:21 +0200 Subject: [PATCH] MIGRATE to use `qs` since that's what we use in many other places --- lib/channel-postmessage/package.json | 1 + lib/channel-postmessage/src/index.ts | 15 ++++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/channel-postmessage/package.json b/lib/channel-postmessage/package.json index 962dc252d0a..b8407b9ea79 100644 --- a/lib/channel-postmessage/package.json +++ b/lib/channel-postmessage/package.json @@ -33,6 +33,7 @@ "@storybook/core-events": "6.0.0-beta.39", "core-js": "^3.0.1", "global": "^4.3.2", + "qs": "^6.6.0", "telejson": "^4.0.0" }, "publishConfig": { diff --git a/lib/channel-postmessage/src/index.ts b/lib/channel-postmessage/src/index.ts index 5a6eceff8f8..195a60f67a4 100644 --- a/lib/channel-postmessage/src/index.ts +++ b/lib/channel-postmessage/src/index.ts @@ -3,6 +3,7 @@ import * as EVENTS from '@storybook/core-events'; import Channel, { ChannelEvent, ChannelHandler } from '@storybook/channels'; import { logger, pretty } from '@storybook/client-logger'; import { isJSON, parse, stringify } from 'telejson'; +import qs from 'qs'; interface Config { page: 'manager' | 'preview'; @@ -14,16 +15,6 @@ interface BufferedEvent { reject: (reason?: any) => void; } -const getQueryObject = (): Record => { - return (window.document.location.search as string) - .substr(1) - .split('&') - .reduce((acc, s) => { - const [k, v] = s.split('='); - return Object.assign(acc, { [k]: v || true }); - }, {}); -}; - export const KEY = 'storybook-channel'; // TODO: we should export a method for opening child windows here and keep track of em. @@ -81,11 +72,13 @@ export class PostmsgTransport { const frames = this.getFrames(target); + const query = qs.parse(location.search, { ignoreQueryPrefix: true }); + const data = stringify( { key: KEY, event, - refId: getQueryObject().refId, + refId: query.refId, }, { maxDepth: depth, allowFunction } );