mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-11 00:06:25 +08:00
CHANGE so frames for channel are filtered to only "ready" frames & flush events when frame loaded in after & on connect flush targets local/main frame
This commit is contained in:
parent
1e178b6426
commit
6abdbd7cbc
@ -45,7 +45,7 @@ export class PostmsgTransport {
|
|||||||
this.handler = (...args) => {
|
this.handler = (...args) => {
|
||||||
handler.apply(this, args);
|
handler.apply(this, args);
|
||||||
|
|
||||||
if (!this.connected && this.getFrames().length) {
|
if (!this.connected && this.getLocalFrame().length) {
|
||||||
this.flush();
|
this.flush();
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
}
|
}
|
||||||
@ -79,6 +79,15 @@ export class PostmsgTransport {
|
|||||||
{ maxDepth: depth, allowFunction }
|
{ maxDepth: depth, allowFunction }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!frames.length) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.buffer.push({ event, resolve, reject });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (frames.length && this.buffer.length) {
|
||||||
|
this.flush();
|
||||||
|
}
|
||||||
|
|
||||||
frames.forEach(f => {
|
frames.forEach(f => {
|
||||||
try {
|
try {
|
||||||
f.postMessage(data, '*');
|
f.postMessage(data, '*');
|
||||||
@ -87,12 +96,6 @@ export class PostmsgTransport {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!frames.length || this.buffer.length) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.buffer.push({ event, resolve, reject });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +112,7 @@ export class PostmsgTransport {
|
|||||||
private getFrames(target?: string): Window[] {
|
private getFrames(target?: string): Window[] {
|
||||||
if (this.config.page === 'manager') {
|
if (this.config.page === 'manager') {
|
||||||
const nodes: HTMLIFrameElement[] = [
|
const nodes: HTMLIFrameElement[] = [
|
||||||
...document.querySelectorAll('iframe[data-is-storybook]'),
|
...document.querySelectorAll('iframe[data-is-storybook][data-is-loaded]'),
|
||||||
];
|
];
|
||||||
|
|
||||||
const list = nodes
|
const list = nodes
|
||||||
@ -145,6 +148,18 @@ export class PostmsgTransport {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getLocalFrame(): Window[] {
|
||||||
|
if (this.config.page === 'manager') {
|
||||||
|
const list: HTMLIFrameElement[] = [...document.querySelectorAll('#storybook-preview-iframe')];
|
||||||
|
return list.map(e => e.contentWindow);
|
||||||
|
}
|
||||||
|
if (window && window.parent) {
|
||||||
|
return [window.parent];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
private handleEvent(rawEvent: MessageEvent): void {
|
private handleEvent(rawEvent: MessageEvent): void {
|
||||||
try {
|
try {
|
||||||
const { data } = rawEvent;
|
const { data } = rawEvent;
|
||||||
|
@ -81,6 +81,7 @@ export class IFrame extends Component<IFrameProps & IframeHTMLAttributes<HTMLIFr
|
|||||||
const { id, title, src, allowFullScreen, scale, active, ...rest } = this.props;
|
const { id, title, src, allowFullScreen, scale, active, ...rest } = this.props;
|
||||||
return (
|
return (
|
||||||
<StyledIframe
|
<StyledIframe
|
||||||
|
onLoad={() => this.iframe.setAttribute('data-is-loaded', 'true')}
|
||||||
data-is-storybook={active ? 'true' : 'false'}
|
data-is-storybook={active ? 'true' : 'false'}
|
||||||
scrolling="yes"
|
scrolling="yes"
|
||||||
id={id}
|
id={id}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user