Skip to content

Commit 5e5b3ce

Browse files
authored
Merge pull request #4120 from Nixxx19/nityam/fix-firefox-scrollbar-4046
fix firefox scrollbar from fractional split pane size
2 parents ffc7d14 + 7eaa290 commit 5e5b3ce

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

client/jest.setup.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ import 'regenerator-runtime/runtime';
55
// See: https://github.com/testing-library/jest-dom
66
// eslint-disable-next-line import/no-extraneous-dependencies
77
import '@testing-library/jest-dom';
8+
9+
global.ResizeObserver = class {
10+
observe() {}
11+
12+
unobserve() {}
13+
14+
disconnect() {}
15+
};

client/modules/IDE/components/PreviewFrame.jsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import React, { useRef, useEffect } from 'react';
1+
import React, { useRef, useEffect, useState } from 'react';
22
import PropTypes from 'prop-types';
33
import styled from 'styled-components';
44
import { getConfig } from '../../../utils/getConfig';
55
import { registerFrame } from '../../../utils/dispatcher';
66

77
const Frame = styled.iframe`
8-
min-height: 100%;
9-
min-width: 100%;
8+
display: block;
109
position: ${(props) => (props.fullView ? 'relative' : 'absolute')};
1110
border-width: 0;
1211
`;
1312

1413
function PreviewFrame({ fullView, isOverlayVisible }) {
1514
const iframe = useRef();
15+
const [frameSize, setFrameSize] = useState(null);
1616
const previewUrl = getConfig('PREVIEW_URL');
1717
useEffect(() => {
1818
const unsubscribe = registerFrame(iframe.current.contentWindow, previewUrl);
@@ -21,6 +21,26 @@ function PreviewFrame({ fullView, isOverlayVisible }) {
2121
};
2222
});
2323

24+
useEffect(() => {
25+
const parent = iframe.current?.parentElement;
26+
if (!parent) {
27+
return () => {};
28+
}
29+
const updateSize = () => {
30+
const { width, height } = parent.getBoundingClientRect();
31+
setFrameSize({
32+
width: Math.floor(width),
33+
height: Math.floor(height)
34+
});
35+
};
36+
updateSize();
37+
const observer = new ResizeObserver(updateSize);
38+
observer.observe(parent);
39+
return () => {
40+
observer.disconnect();
41+
};
42+
}, []);
43+
2444
const frameUrl = previewUrl;
2545
const sandboxAttributes = `allow-forms allow-modals allow-pointer-lock allow-popups
2646
allow-same-origin allow-scripts allow-top-navigation-by-user-activation allow-downloads`;
@@ -45,6 +65,11 @@ function PreviewFrame({ fullView, isOverlayVisible }) {
4565
frameBorder="0"
4666
ref={iframe}
4767
fullView={fullView}
68+
style={
69+
frameSize
70+
? { width: frameSize.width, height: frameSize.height }
71+
: undefined
72+
}
4873
/>
4974
</>
5075
);

0 commit comments

Comments
 (0)