Skip to content

Commit 463b5e2

Browse files
committed
fix(autoHeightBridge): simplify height measurement, ensure body/html sizing, and extend update timeouts
- remove getMaxHeight helper and measure using documentElement/body scroll/offset metrics - ensure body/html have height: auto and minHeight/width set for accurate measurement - force layout recalculation by reading html.offsetHeight before measuring - add longer delayed update timeouts (3000ms, 5000ms) to improve stability
1 parent 0bbb163 commit 463b5e2

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/constants/autoHeightBridge.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,24 @@ export const AUTO_HEIGHT_BRIDGE = `(() => {
4747
return 0;
4848
};
4949
50-
const getMaxHeight = (element) => {
51-
if (!element) {
52-
return 0;
53-
}
54-
return Math.max(
55-
element.scrollHeight || 0,
56-
element.offsetHeight || 0,
57-
element.clientHeight || 0
58-
);
59-
};
60-
6150
const measureDocumentHeight = () => {
62-
const scrollingElement = document.scrollingElement;
63-
const body = document.body;
6451
const html = document.documentElement;
52+
const body = document.body;
53+
54+
// Ensure body has proper styling for measurement
55+
if (body) {
56+
body.style.height = 'auto';
57+
body.style.minHeight = '100%';
58+
}
59+
60+
// Force layout recalculation
61+
const forceLayout = html.offsetHeight;
6562
6663
return Math.max(
67-
getMaxHeight(scrollingElement),
68-
getMaxHeight(body),
69-
getMaxHeight(html)
64+
html.scrollHeight,
65+
html.offsetHeight,
66+
body ? body.scrollHeight : 0,
67+
body ? body.offsetHeight : 0
7068
);
7169
};
7270
@@ -132,12 +130,16 @@ export const AUTO_HEIGHT_BRIDGE = `(() => {
132130
if (html) {
133131
html.style.overflow = 'hidden';
134132
html.style.backgroundColor = 'transparent';
133+
html.style.height = 'auto';
135134
}
136135
137136
const body = document.body;
138137
if (body) {
139138
body.style.backgroundColor = 'transparent';
140139
body.style.margin = '0';
140+
body.style.width = '100%';
141+
body.style.height = 'auto';
142+
body.style.minHeight = '100%';
141143
}
142144
};
143145
@@ -252,7 +254,7 @@ export const AUTO_HEIGHT_BRIDGE = `(() => {
252254
attachGlobalListeners();
253255
scheduleHeightUpdate();
254256
255-
const timeouts = [16, 60, 180, 500, 1000, 2000];
257+
const timeouts = [16, 60, 180, 500, 1000, 2000, 3000, 5000];
256258
for (let index = 0; index < timeouts.length; index += 1) {
257259
setTimeout(scheduleHeightUpdate, timeouts[index]);
258260
}

0 commit comments

Comments
 (0)