feat(joint-core): auto-emit 'resize' when host element CSS size changes#3318
Merged
Geliogabalus merged 4 commits intoMay 19, 2026
Merged
Conversation
`dia.Paper` now attaches a ResizeObserver to its host `<div>` and re-emits
the existing `'resize'` event when the host's computed size changes. This
makes downstream subscribers — `GridLayerView`, `PaperScroller`, rulers,
the React host — track CSS-relative sizing (`width: null`/`'100%'`/flex/
container queries) without manual `setDimensions()` calls. The observer
self-skips when both `options.width` and `options.height` are numeric,
preserving the explicit-size contract. New opt-out: `autoResizePaper: false`.
Auto-emitted events carry `{ source: 'observer' }` as `data` so listeners
can distinguish them from explicit `setDimensions()` emissions.
https://claude.ai/code/session_013FyjBbiuXq4gr3ZRkT4Uvz
Geliogabalus
approved these changes
May 19, 2026
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
dia.Papernow attaches aResizeObserverto its host<div>and re-emits the existing'resize'event when the host's computed size changes. Downstream subscribers —GridLayerView,PaperScroller, rulers, custom listeners — automatically follow CSS-relative sizing (width: null/'100%'/ flex / container queries) without manualsetDimensions()calls.The observer self-skips when both
options.widthandoptions.heightare numeric, so the existing explicit-size contract is preserved. Auto-emitted events carry{ source: 'observer' }as thedataargument so listeners doing expensive work can short-circuit on it.Motivation
Paper#getComputedSize()already falls back toel.clientWidth/el.clientHeightwhenoptions.width/heightare non-numeric, so CSS-relative sizing works — but JointJS never learned when the host actually changed size. The'resize'event only fired from explicitsetDimensions()calls, leavingGridLayerViewand other size-aware consumers stale on flex resizes, window resizes, sidebar toggles, container queries, etc.Flow
setDimensions()keeps its own directtrigger('resize', …)for the explicit-API path; both code paths feed_lastObservedSize, so observer + setDimensions never double-fire.Changes
packages/joint-core/src/dia/Paper.mjs_startObservingElementSize/_stopObservingElementSizeand dedup state_lastObservedSize.init(),onRemove(), andsetDimensions()(re-evaluates observer attachment when toggling between explicit and CSS-relative modes).packages/joint-core/test/jointjs/paper.js— QUnit tests covering fire / skip / teardown / toggle paths.Test plan
yarn workspace @joint/core test— full QUnit + Mocha suite green.yarn workspace @joint/core run test-ts— TS pass.width/height. Confirm no extra'resize'events fire on window resize.ResizeObserver#disconnectis called exactly once perpaper.remove().🤖 Generated with Claude Code