fix(web): Safari work items crash from requestIdleCallback#8975
fix(web): Safari work items crash from requestIdleCallback#8975rbshh wants to merge 4 commits intomakeplane:previewfrom
Conversation
📝 WalkthroughWalkthroughPolyfill initialization for requestIdleCallback/cancelIdleCallback was centralized into a reusable helper ( Changes
Sequence Diagram(s)sequenceDiagram
participant ClientEntry as Client Entry
participant Polyfill as scheduleIdleCallback (polyfills)
participant Browser as Browser Window
participant HOC as RenderIfVisible HOC
ClientEntry->>Polyfill: import (ensure polyfills installed)
Polyfill->>Browser: install requestIdleCallback / cancelIdleCallback if missing
ClientEntry->>Browser: startTransition / hydrateRoot
HOC->>Polyfill: scheduleIdleCallback(callback, options)
Polyfill->>Browser: forward to window.requestIdleCallback or noop (SSR)
Browser-->>HOC: idle callback invoked
HOC-->>Browser: IntersectionObserver observes element
Browser-->>HOC: intersection events -> HOC schedules idle work via polyfill
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/core/components/core/render-if-visible-HOC.tsx (1)
50-76:⚠️ Potential issue | 🟡 MinorAdd
useIdletimeto the observer effect dependencies.
useIdletimeis read in Line 55, but it’s missing from the dependency array in Line 76. If that prop toggles at runtime, observer behavior can stay stale.💡 Suggested fix
- }, [intersectionRef, children, root, verticalOffset, horizontalOffset]); + }, [intersectionRef, children, root, verticalOffset, horizontalOffset, useIdletime]);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/core/components/core/render-if-visible-HOC.tsx` around lines 50 - 76, The effect in useEffect that creates the IntersectionObserver reads the useIdletime variable but does not include it in the dependency array; update the dependency array for that effect (the useEffect that references intersectionRef, children, root, verticalOffset, horizontalOffset) to also include useIdletime so changes to useIdletime will recreate the observer and ensure scheduleIdleCallback/setShouldVisible behavior stays in sync.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@apps/web/core/components/core/render-if-visible-HOC.tsx`:
- Around line 50-76: The effect in useEffect that creates the
IntersectionObserver reads the useIdletime variable but does not include it in
the dependency array; update the dependency array for that effect (the useEffect
that references intersectionRef, children, root, verticalOffset,
horizontalOffset) to also include useIdletime so changes to useIdletime will
recreate the observer and ensure scheduleIdleCallback/setShouldVisible behavior
stays in sync.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 473b3685-585e-46ec-a97e-9a6c5ba638fb
📒 Files selected for processing (3)
apps/web/app/entry.client.tsxapps/web/core/components/core/render-if-visible-HOC.tsxapps/web/core/lib/polyfills/index.ts
…mline scheduleIdleCallback export
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/web/core/components/core/render-if-visible-HOC.tsx`:
- Line 77: The effect that creates the IntersectionObserver (the useEffect
associated with intersectionRef and variables root, verticalOffset,
horizontalOffset, useIdletime) incorrectly includes children in its dependency
array causing unnecessary re-creation; remove children from the dependency list
so the observer only depends on intersectionRef, root, verticalOffset,
horizontalOffset, and useIdletime (or add an eslint-disable-next-line comment if
a linter complains) and ensure the observer creation/cleanup logic in the same
function remains unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d95ce9a9-4dd3-4de4-a793-d06d5c73ae9a
📒 Files selected for processing (2)
apps/web/core/components/core/render-if-visible-HOC.tsxapps/web/core/lib/polyfills/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/web/core/lib/polyfills/index.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
@sriramveeraghanta can we prioritize this? I believe it's a something critical for Safari Users. |
Description
RenderIfVisiblecallswindow.requestIdleCallbackwhen recording row heights after visible render. Safari (+WebKit) lacks this API.A polyfill existed in
core/lib/polyfills/index.tsbut was never imported, so the runtime still threw.Changes
entry.client.tsxbefore hydration.scheduleIdleCallback()that applies the idle polyfill idempotently and delegates.window.requestIdleCallbackusage inrender-if-visible-HOC.tsxwithscheduleIdleCallback.typeof window !== undefinedcheck (use"undefined").Type of Change
Screenshots and Media (if applicable)
Test Scenarios
requestIdleCallback).References
Closes #8904
Closes #8871
Related to #5689 (the original polyfill PR — this completes its intent for lazy-loaded chunks)
Could be duplicate of PR #8937
Summary by CodeRabbit