Skip to content

fix: redraw the timeline when console panels resize the canvas - #359

Merged
deejay-hub merged 1 commit into
mainfrom
feat/console-panel-resize
Aug 20, 2026
Merged

fix: redraw the timeline when console panels resize the canvas#359
deejay-hub merged 1 commit into
mainfrom
feat/console-panel-resize

Conversation

@deejay-hub

Copy link
Copy Markdown
Owner

Summary

Resizing the browser window redrew the timeline correctly, but Salesforce console apps slide docked panels and utility bars in and out without changing the viewport. No resize event fires, so the canvas kept rendering at its old width until something else forced a redraw.

The component now watches the canvas element with a ResizeObserver instead of listening on window, which catches any change to the drawing area regardless of what caused it — including plain window resizes, so it fully replaces the old listener.

  • Redraws are debounced (200ms) and deferred to the next animation frame. The debounce absorbs the stream of intermediate sizes emitted while a panel animates, and the frame deferral avoids the "ResizeObserver loop completed with undelivered notifications" error that measuring inside the callback can trigger.
  • A new _lastCanvasWidth field means height-only changes and duplicate notifications no longer cause pointless redraws. It is seeded during the initial draw in timelineCanvas().
  • A zero width means the component is hidden, which is what happens in a background console tab. Previously the timeline could stay stuck at a stale width after being hidden and re-shown; the observer now fires when it becomes visible again and the canvas re-fits.
  • The observer is disconnected and any pending frame cancelled in disconnectedCallback, which matters in console apps where tabs are opened and closed constantly.

Lightning Locker

ResizeObserver is not available under Lightning Locker, where it is either missing outright or reported as "not a constructor". Locker is still the default in orgs created before Winter '23 and has no announced retirement date, so attaching the observer is feature-detected and wrapped in try/catch, falling back to the previous window resize listener.

That fallback does not fix the panel case in Locker orgs, which is a deliberate trade-off: the alternative was polling the canvas width on an interval, which is not worth the ongoing cost for a legacy security architecture. Locker orgs keep exactly the behaviour they have today rather than regressing.

Test plan

  • npm test — three new tests cover the observer being attached and disconnected, ResizeObserver missing, and ResizeObserver present but not constructible (the last two assert the window listener is added and removed)
  • npx eslint clean
  • Deployed to a scratch org (API 67, LWS enabled)
  • In a console app, slide a docked panel or the utility bar in and out without resizing the window and confirm the timeline re-fits
  • Switch to another console tab and back, and confirm the timeline re-fits after being hidden

Note: the jsdom test environment has no ResizeObserver, which mirrors Locker, so the observer test injects a mock.

Console apps slide docked panels and utility bars in and out without
changing the viewport, so the window resize listener never fired and the
timeline kept rendering at its old width. Watch the canvas element with a
ResizeObserver instead, which also picks up the component becoming visible
again after being hidden in a background console tab.

ResizeObserver is unavailable under Lightning Locker, so attaching it is
guarded and falls back to the previous window resize listener. That leaves
Locker orgs with the existing panel behaviour rather than a regression.
@deejay-hub
deejay-hub merged commit c000d49 into main Aug 20, 2026
2 checks passed
@deejay-hub
deejay-hub deleted the feat/console-panel-resize branch August 20, 2026 01:18
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