Skip to content

Commit 9e88a20

Browse files
committed
fix(autoHeightBridge): post rounded CSS height and add anomaly guard
- remove density-based normalization (devicePixelRatio/visualViewport) and post Math.ceil(height) - add anomalyCount to detect extreme heights (>100000), retry measurement a few times before ignoring - preserve lastHeight dedupe to avoid duplicate posts
1 parent bce0d77 commit 9e88a20

File tree

1 file changed

+17
-40
lines changed

1 file changed

+17
-40
lines changed

src/constants/autoHeightBridge.ts

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const AUTO_HEIGHT_BRIDGE = `(() => {
4242
pendingLoads: 0,
4343
lastHeight: 0,
4444
lastCssHeight: 0,
45+
anomalyCount: 0,
4546
fallbackTimer: null,
4647
fallbackDelay: INITIAL_FALLBACK_MS,
4748
cleanup: [],
@@ -224,63 +225,39 @@ export const AUTO_HEIGHT_BRIDGE = `(() => {
224225
return Math.max(0, Math.ceil(readMaxValue(values)));
225226
};
226227
227-
var normalizeHeight = function (height) {
228-
if (!height || !isFinite(height) || height <= 0) {
229-
return 0;
230-
}
231-
232-
var pixelRatio =
233-
typeof window.devicePixelRatio === 'number' &&
234-
window.devicePixelRatio > 0
235-
? window.devicePixelRatio
236-
: 1;
237-
238-
var viewport = window.visualViewport;
239-
var viewportScale =
240-
viewport && typeof viewport.scale === 'number' && viewport.scale > 0
241-
? viewport.scale
242-
: 1;
243-
244-
var density = pixelRatio / viewportScale;
245-
if (!density || density <= 0) {
246-
density = 1;
247-
}
248-
249-
var normalized = Math.ceil(height / density + 0.01);
250-
251-
if (!isFinite(normalized) || normalized <= 0) {
252-
return 0;
253-
}
254-
255-
if (normalized > 2147483647) {
256-
normalized = 2147483647;
257-
}
258-
259-
return normalized;
260-
};
261-
262228
var postHeight = function (height) {
263229
if (!height || height <= 0) {
264230
return;
265231
}
266232
267233
state.lastCssHeight = height;
268234
269-
var normalized = normalizeHeight(height);
270-
if (!normalized) {
235+
var sanitized = Math.ceil(height);
236+
237+
if (!isFinite(sanitized) || sanitized <= 0) {
271238
return;
272239
}
273240
274-
if (state.lastHeight === normalized) {
241+
if (sanitized > 100000) {
242+
state.anomalyCount += 1;
243+
if (state.anomalyCount < 3) {
244+
scheduleMeasure(true);
245+
return;
246+
}
247+
} else {
248+
state.anomalyCount = 0;
249+
}
250+
251+
if (state.lastHeight === sanitized) {
275252
return;
276253
}
277254
278-
state.lastHeight = normalized;
255+
state.lastHeight = sanitized;
279256
280257
try {
281258
var channel = window.ReactNativeWebView;
282259
if (channel && typeof channel.postMessage === 'function') {
283-
channel.postMessage(String(normalized));
260+
channel.postMessage(String(sanitized));
284261
}
285262
} catch (error) {
286263
// no-op

0 commit comments

Comments
 (0)