Skip to content

Commit

Permalink
Merge pull request #16764 from storybookjs/fix/12364-channel-options-…
Browse files Browse the repository at this point in the history
…overridden-by-defaults

Core: Fix channel options so that they are merged in correct order
  • Loading branch information
shilman committed Nov 24, 2021
2 parents c67c22a + c61f83d commit 9c9625a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/channel-postmessage/src/index.ts
Expand Up @@ -19,6 +19,8 @@ interface BufferedEvent {

export const KEY = 'storybook-channel';

const defaultEventOptions = { allowFunction: true, maxDepth: 25 };

// TODO: we should export a method for opening child windows here and keep track of em.
// that way we can send postMessage to child windows as well, not just iframe
// https://stackoverflow.com/questions/6340160/how-to-get-the-references-of-all-already-opened-child-windows
Expand Down Expand Up @@ -63,17 +65,17 @@ export class PostmsgTransport {

// telejson options
allowRegExp,
allowFunction = true,
allowFunction,
allowSymbol,
allowDate,
allowUndefined,
allowClass,
maxDepth = 25,
maxDepth,
space,
lazyEval,
} = options || {};

const c = Object.fromEntries(
const eventOptions = Object.fromEntries(
Object.entries({
allowRegExp,
allowFunction,
Expand All @@ -87,7 +89,11 @@ export class PostmsgTransport {
}).filter(([k, v]) => typeof v !== 'undefined')
);

const stringifyOptions = { ...(global.CHANNEL_OPTIONS || {}), ...c };
const stringifyOptions = {
...defaultEventOptions,
...(global.CHANNEL_OPTIONS || {}),
...eventOptions,
};

// backwards compat: convert depth to maxDepth
if (options && Number.isInteger(options.depth)) {
Expand Down

0 comments on commit 9c9625a

Please sign in to comment.