Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

πŸ”Š Filter benign ResizeObserver loop notice from error tracking (#2987)

posthog-eu[bot]8e75e82d7afa
diff --git a/apps/web/src/components/scroll-container.tsx b/apps/web/src/components/scroll-container.tsx
index cbc96f8a3..9cdd4a0f2 100644
--- a/apps/web/src/components/scroll-container.tsx
+++ b/apps/web/src/components/scroll-container.tsx
@@ -8,14 +8,23 @@ const useIsOverflowing = <E extends Element | null>(
const [isOverflowing, setIsOverflowing] = React.useState(false);
React.useEffect(() => {
+ // Defer the state update to the next frame so it lands outside the
+ // ResizeObserver callback's frame. Updating layout state inline can resize
+ // the observed element again in the same frame, which makes the browser fire
+ // "ResizeObserver loop completed with undelivered notifications." on
+ // window.onerror.
+ let frame = 0;
const checkOverflow = () => {
- if (ref.current) {
- const element = ref.current;
- const overflowX = element.scrollWidth > element.clientWidth;
- const overflowY = element.scrollHeight > element.clientHeight;
+ cancelAnimationFrame(frame);
+ frame = requestAnimationFrame(() => {
+ if (ref.current) {
+ const element = ref.current;
+ const overflowX = element.scrollWidth > element.clientWidth;
+ const overflowY = element.scrollHeight > element.clientHeight;
- setIsOverflowing(overflowX || overflowY);
- }
+ setIsOverflowing(overflowX || overflowY);
+ }
+ });
};
if (ref.current) {
@@ -31,6 +40,7 @@ const useIsOverflowing = <E extends Element | null>(
checkOverflow();
return () => {
+ cancelAnimationFrame(frame);
resizeObserver.disconnect();
mutationObserver.disconnect();
};
diff --git a/packages/posthog/src/client.ts b/packages/posthog/src/client.ts
index 2c3d87263..d91ff55e0 100644
--- a/packages/posthog/src/client.ts
+++ b/packages/posthog/src/client.ts
@@ -7,6 +7,7 @@ import {
isAbortError,
isGlobalPrivacyControlEnabled,
isInjectedExtensionException,
+ isResizeObserverLoopError,
} from "./utils";
if (typeof window !== "undefined" && process.env.NEXT_PUBLIC_POSTHOG_API_KEY) {
@@ -27,7 +28,9 @@ if (typeof window !== "undefined" && process.env.NEXT_PUBLIC_POSTHOG_API_KEY) {
before_send: (event) => {
if (
event?.event === "$exception" &&
- (isInjectedExtensionException(event) || isAbortError(event))
+ (isInjectedExtensionException(event) ||
+ isAbortError(event) ||
+ isResizeObserverLoopError(event))
) {
return null;
}
diff --git a/packages/posthog/src/utils.test.ts b/packages/posthog/src/utils.test.ts
index 6041681d2..f5dbba6e6 100644
--- a/packages/posthog/src/utils.test.ts
+++ b/packages/posthog/src/utils.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
import {
getPostHogCookieName,
isAbortError,
+ isResizeObserverLoopError,
parsePostHogCookieDistinctId,
} from "./utils";
@@ -60,6 +61,51 @@ describe("isAbortError", () => {
});
});
+describe("isResizeObserverLoopError", () => {
+ const event = (exceptionList: unknown) =>
+ ({
+ properties: { $exception_list: exceptionList },
+ }) as unknown as CaptureResult;
+
+ it("matches the undelivered notifications notice", () => {
+ expect(
+ isResizeObserverLoopError(
+ event([
+ {
+ type: "Error",
+ value:
+ "ResizeObserver loop completed with undelivered notifications.",
+ },
+ ]),
+ ),
+ ).toBe(true);
+ });
+
+ it("matches the loop limit exceeded notice", () => {
+ expect(
+ isResizeObserverLoopError(
+ event([{ type: "Error", value: "ResizeObserver loop limit exceeded" }]),
+ ),
+ ).toBe(true);
+ });
+
+ it("does not match an unrelated exception", () => {
+ expect(
+ isResizeObserverLoopError(
+ event([{ type: "TypeError", value: "x is not a function" }]),
+ ),
+ ).toBe(false);
+ });
+
+ it("does not match when the exception list is missing", () => {
+ expect(
+ isResizeObserverLoopError({
+ properties: {},
+ } as unknown as CaptureResult),
+ ).toBe(false);
+ });
+});
+
describe("parsePostHogCookieDistinctId", () => {
it("parses a URL-encoded JSON cookie value", () => {
const value = encodeURIComponent(
diff --git a/packages/posthog/src/utils.ts b/packages/posthog/src/utils.ts
index 84a2b9c72..772c5ab51 100644
--- a/packages/posthog/src/utils.ts
+++ b/packages/posthog/src/utils.ts
@@ -113,3 +113,29 @@ export function isAbortError(event: CaptureResult) {
ABORT_NOISE_VALUE_PATTERN.test(exception.value)),
);
}
+
+/**
+ * The browser fires `ResizeObserver loop completed with undelivered
+ * notifications.` on `window.onerror` when a ResizeObserver callback changes
+ * layout and the browser cannot deliver every notification inside one animation
+ * frame. Nothing breaks β€” it is a notice, not a crash β€” so autocapture must not
+ * report it as a real error.
+ */
+const RESIZE_OBSERVER_LOOP_VALUE_PATTERN =
+ /^ResizeObserver loop (limit exceeded|completed with undelivered notifications)/i;
+
+export function isResizeObserverLoopError(event: CaptureResult) {
+ const exceptionList = event.properties?.$exception_list as
+ | Array<{ value?: string }>
+ | undefined;
+
+ if (!Array.isArray(exceptionList)) {
+ return false;
+ }
+
+ return exceptionList.some(
+ (exception) =>
+ typeof exception?.value === "string" &&
+ RESIZE_OBSERVER_LOOP_VALUE_PATTERN.test(exception.value),
+ );
+}