Repository navigation
Conversation
…seOnElementsMeasured - store/measurement.ts replaces create-elements-size-observer.ts and the measurement code in graph-store, graph-changes and graph-projection; the ResizeObserver is created by the first observe() - useOnElementsMeasured: one event per settled change, a removal included; zero-sized elements count as measured; elements of an external graph are tracked from the start; an unmounted measured node no longer blocks events; the event is announced once the measured sizes are in the store - useCells runs on an internal graph-state reader that subscribes to what its selector reads; an inline selector capturing a changed prop is re-run - scheduler: a throwing callback no longer stops the flush; cascading callbacks continue on a later task; a graph change made by a subscriber during notification is no longer dropped
Contributor
Author
|
closed of favor of this master fix: #3556 |
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.
Description
Measuring elements was spread over
graph-store.ts,graph-changes.ts,graph-projection.tsandcreate-elements-size-observer.ts. This PR moves it into one module that the store core no longer needs to know about, and fixes the cases whereuseOnElementsMeasuredstill fired too early, too late or never. The public API is unchanged: no hook or selector is added, removed or deprecated.src/store/measurement.ts(new, replacescreate-elements-size-observer.ts)createMeasurement({ graph, autoSizeOrigin, paperStores }), exposed asgraphStore.measurement. It owns its ownmvc.Listeneron the graph (add/remove/reset/change:size), the node registry and theResizeObserver.ResizeObserveris created by the firstobserve(), so a diagram that never measures has none.0while nothing is measured, otherwise a value that changes once per settled change and is never reused.useOnElementsMeasuredreads it.graph-store.ts,graph-changes.tsandgraph-projection.tsno longer contain measurement code.use-are-elements-measured.ts(internal) and two dead helpers inclear-view.tsare deleted.useOnElementsMeasured- contractUnchanged from #3518:
cell.resize(), controlledcellssync) are not measurements.Changed (the JSDoc states each):
isInitialis reported again after the last element is removed, as after a reset;graphare tracked from the start;useCellssrc/store/graph-state.ts,use-graph-state.ts, not exported). The reader subscribes to exactly what the selector reads: one cell, the ids of a collection, or all cells.dia.Graph.Store callbacks (
src/utils/scheduler.ts,src/store/graph-projection.ts)These three bugs already exist on
dev:Tests
src/store/__tests__/measurement.test.ts: the observer and graph-changes tests, ported one to one, plus the settled-state cases.use-on-elements-measured-events.test.tsx: the 16 spec cases from test(joint-react): specify how many events useOnElementsMeasured delivers #3520, throughuseOnElementsMeasured.use-on-elements-measured-settling.test.tsx: an unrendered element, removal while waiting or settled, a content change that re-measures.graph-state.test.tsanduse-graph-state.test.tsxcover the reader. They include regression tests for the event-before-commit ordering and a subscription that follows a render React throws away.graph-store.test.tscovers removing the last paper.use-cells.test.tsxcovers the inline-selector fix and the hook name in the dev warning.scheduler.test.tscovers the throwing callback, the cascade cap and changes made during notification.packages/joint-react:yarn test(typecheck + knip + duplicity-detect + jest): 1150 tests on React 19 and 1146 on React 18, all passing.yarn lint: 0 errors.automatic-layout: lays out without overlap, including after "Add node".flowchart,collapsible-subtrees: render as before.Changesets:
@joint/reactpatch:useOnElementsMeasured - fix to fire exactly once per settled change (an addition, a removal or a re-measurement), when no element is still waiting to be measured. This rewrites the unreleased line from fix(joint-react): deliver useOnElementsMeasured once per settled change #3518.@joint/reactpatch:<GraphProvider /> - fix a store callback that throws or changes the graph breaking later updates.@joint/reactpatch:useCells - fix an inline selector that captures a changed prop returning a stale value until the next graph change.Motivation and Context
Follow-up of #3518 (spec in #3520), split out of #3532 so the fixes can ship in the next patch release. #3532 is stacked on this branch and adds only the new public API on top:
useGraphState,useOnGraphStateChange,useOnCellsChange, the sizing selectors, and theuseOnElementsMeasureddeprecation.Notes
devget no CI; the full suite was run locally.yarn bench, withdevand this branch both run on the same machine, is within noise. A hook-level probe (2,000 elements, 2,000 per-celluseCells(id, selector)readers plus two all-cells readers) measures:dev;dev.yarn test-coverageis below its floor ondevalready; this PR does not change that.Screenshots (if appropriate):