Fix height for SandboxFrame (#676)
This commit is contained in:
parent
5d4b193865
commit
6dba2e4792
|
@ -15,6 +15,7 @@ interface SandboxFrameState {
|
||||||
|
|
||||||
export class SandboxFrame extends React.PureComponent<SandboxFrameProps, SandboxFrameState> {
|
export class SandboxFrame extends React.PureComponent<SandboxFrameProps, SandboxFrameState> {
|
||||||
private resizeObserver: ResizeObserver;
|
private resizeObserver: ResizeObserver;
|
||||||
|
private mutationObserver: MutationObserver;
|
||||||
|
|
||||||
constructor(props: SandboxFrameProps) {
|
constructor(props: SandboxFrameProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -43,22 +44,26 @@ export class SandboxFrame extends React.PureComponent<SandboxFrameProps, Sandbox
|
||||||
|
|
||||||
componentWillUnmount(): void {
|
componentWillUnmount(): void {
|
||||||
this.resizeObserver?.disconnect();
|
this.resizeObserver?.disconnect();
|
||||||
|
this.mutationObserver?.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
onFrameLoad(event: React.SyntheticEvent<HTMLIFrameElement, Event>): void {
|
onFrameLoad(event: React.SyntheticEvent<HTMLIFrameElement, Event>): void {
|
||||||
const doc = (event.target as HTMLIFrameElement).contentDocument;
|
const doc = (event.target as HTMLIFrameElement).contentDocument;
|
||||||
copyStyles(document, doc);
|
copyStyles(document, doc);
|
||||||
|
|
||||||
this.setState({
|
this.setState({ frameBody: doc.body });
|
||||||
frameBody: doc.body,
|
|
||||||
frameHeight: doc.body.scrollHeight,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.resizeObserver = new ResizeObserver(() =>
|
this.mutationObserver = new MutationObserver(() => {
|
||||||
this.setState({
|
const bodyFirstElementChild = this.state.frameBody?.firstElementChild;
|
||||||
frameHeight: this.state.frameBody.scrollHeight,
|
if (!this.resizeObserver && bodyFirstElementChild) {
|
||||||
})
|
this.resizeObserver = new ResizeObserver(() =>
|
||||||
);
|
this.setState({
|
||||||
this.resizeObserver.observe(doc.body);
|
frameHeight: this.state.frameBody?.firstElementChild.scrollHeight,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
this.resizeObserver.observe(bodyFirstElementChild);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.mutationObserver.observe(doc.body, { childList: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue