Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Fix channel options so that they are merged in correct order #16764

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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