Skip to content

SCAL-325100 Automate pre-render position tracking via MutationObserver - #604

Open
shivam-kumar-ts wants to merge 9 commits into
mainfrom
SCAL-325100
Open

SCAL-325100 Automate pre-render position tracking via MutationObserver#604
shivam-kumar-ts wants to merge 9 commits into
mainfrom
SCAL-325100

Conversation

@shivam-kumar-ts

@shivam-kumar-ts shivam-kumar-ts commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Previously, the pre-render wrapper only repositioned itself when the placeholder was resized or the container was scrolled — any other layout shift (sidebar collapse, banner insertion, window resize) would leave the wrapper misaligned, and developers had to call syncPreRenderStyle() manually. This PR adds a MutationObserver that watches the placeholder's ancestor chain for both CSS class/style changes and DOM insertions/removals, a window resize listener, and routes all three signals through a requestAnimationFrame debounce gate so rapid mutations collapse into a single position measurement taken after the browser finishes layout. The scroll listener is also unified to go through the same rAF path instead of firing on every scroll tick. Together, the wrapper now automatically stays aligned with the placeholder across all common layout shift patterns with no manual developer intervention required.

/**
     * Starts a MutationObserver that watches the placeholder's ancestor chain
     * for layout-triggering DOM changes and syncs the pre-render wrapper
     * position when the placeholder actually moves.
     *
     * Three signal sources are combined:
     *  1. `attributes` (class/style) on ancestors — CSS-driven layout shifts
     *     (sidebar collapse, theme toggle, etc.)
     *  2. `childList` on ancestors — element additions/removals that push
     *     content around (notification banners, inserted panels, etc.)
     *  3. `window` resize — viewport changes that shift position without
     *     resizing the placeholder itself.
     *
     * All signals are funnelled through a single `requestAnimationFrame`
     * gate so that (a) rapid mutation bursts collapse into one measurement
     * and (b) `getBoundingClientRect()` is called after the browser has
     * finished computing layout, avoiding mid-transition readings.
     */
// Walk ancestors from the placeholder up to (and including) the
        // container boundary. Both attribute mutations (class/style toggles)
        // and childList mutations (added/removed siblings) on any ancestor
        // can shift the placeholder's position without changing its size.

@shivam-kumar-ts
shivam-kumar-ts requested a review from a team as a code owner July 29, 2026 11:16
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@thoughtspot/visual-embed-sdk@604

commit: b6e2d42

@shivam-kumar-ts shivam-kumar-ts changed the title SCAL-325100 Automate pre-render position sync via MutationObserver SCAL-325100 Automate pre-render position tracking via MutationObserver Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant