fix: redraw the timeline when console panels resize the canvas - #359
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
resizeevent 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
ResizeObserverinstead of listening onwindow, which catches any change to the drawing area regardless of what caused it — including plain window resizes, so it fully replaces the old listener._lastCanvasWidthfield means height-only changes and duplicate notifications no longer cause pointless redraws. It is seeded during the initial draw intimelineCanvas().disconnectedCallback, which matters in console apps where tabs are opened and closed constantly.Lightning Locker
ResizeObserveris 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 intry/catch, falling back to the previouswindowresize 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,ResizeObservermissing, andResizeObserverpresent but not constructible (the last two assert the window listener is added and removed)npx eslintcleanNote: the jsdom test environment has no
ResizeObserver, which mirrors Locker, so the observer test injects a mock.