Skip to content

fix(calm-hub-ui): stop the React Flow nodeTypes warning under StrictMode - #3665

Merged
markscott-ms merged 3 commits into
finos:mainfrom
Mittalnew:fix/react-flow-12-nodetypes-warning-3506
Nov 13, 2026
Merged

markscott-ms merged 3 commits into
finos:mainfrom
Mittalnew:fix/react-flow-12-nodetypes-warning-3506

Conversation

@Mittalnew

Copy link
Copy Markdown
Contributor

Description

Fixes #3506

React Flow 11 reports error 002 (new nodeTypes or edgeTypes object) from a useMemo that React StrictMode runs twice on mount. ArchitectureGraph, PatternGraph and DiffGraph already define nodeTypes and edgeTypes as module constants, so this is a false positive that only shows in development.

This upgrades calm-hub-ui from reactflow 11 to @xyflow/react 12, which moved the check into useEffect and compares the type components themselves. Stable module constants no longer warn, and a real change to a node or edge type still reports 002.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)

Affected Components

  • CALM Hub UI (calm-hub-ui/)
  • Dependencies

Commit Message Format ✅

fix(calm-hub-ui): stop the React Flow nodeTypes warning under StrictMode

Testing

  • I have tested my changes locally
  • I have added/updated unit tests
  • All existing tests pass

Added a StrictMode unit test that renders ReactFlow with module-level nodeTypes/edgeTypes and asserts that error 002 is not reported, plus a test that 002 still fires when a type component actually changes. Lint, the Vite production build, and the full calm-hub-ui Vitest suite (2230 tests) pass.

This also addresses the review feedback on the earlier closed PR #3560: ignoring 002 in onError could not work, because React Flow 11 raises the warning during the first render before onError is written to the store, and a handler that logged other errors in production would not have matched the default dev-only behaviour. This change fixes the underlying StrictMode interaction instead of suppressing the warning.

Checklist

  • My commits follow the conventional commit format
  • I have updated documentation if necessary
  • I have added tests for my changes (if applicable)
  • My changes follow the project's coding standards

I have signed the FINOS CLA.

React Flow 11 reports error 002 from a useMemo that StrictMode runs twice
on mount, even when nodeTypes and edgeTypes are already module constants.
Upgrading to @xyflow/react 12 moves that check into useEffect and compares
the type components themselves, so the false positive goes away without
suppressing the warning.

Fixes finos#3506
@Mittalnew
Mittalnew requested a review from a team as a code owner November 12, 2026 07:44
@github-actions github-actions Bot added config calm-hub-ui Affects `calm-hub-ui` labels Nov 12, 2026
Comment thread package-lock.json Resolved

@markscott-ms markscott-ms left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Mittalnew. Moving to @xyflow/react 12 is a good fix for #3506: it removes the false warning at the source instead of hiding it, and the new StrictMode test shows that a real node type change still reports error 002.

Two changes are necessary before merge. Both come from one change in React Flow 12:

In React Flow 11, node.width and node.height were outputs: React Flow measured each node and wrote its size there, so it did not matter if our code set them. In React Flow 12 they are inputs: if they are set, React Flow draws the node at exactly that size (getNodeInlineStyleDimensions). The measured size is now in node.measured.

1. A restored layout fixes the size of each card

applyPositions in node-position-service.tsx sets the stored width and height on every node, including custom cards. A card sizes itself to its text, which the diagram text size and presentation mode change. In v11 this was harmless. In v12 it fixes the card at the stored size.

Example: save a layout at 100% text size. Then increase the diagram text size, or enter presentation mode. The cards do not grow, so the text overflows the box. This is the "stale box" that the comment in applyPositions says the code avoids. Each drag then saves the fixed size again, so it is never corrected.

Fix: do not set width and height on custom nodes in applyPositions. Containers can keep them.

2. Enlarged card sizes are saved for all viewers

When the text size is not 100%, or in presentation mode, useGraphInteractions removes the card sizes before it reflows the containers and saves the layout ({ ...node, width: undefined, height: undefined }). The intent is that the saved layout uses the normal card size, not one viewer's enlarged size. In v12 the spread keeps node.measured, and the new ?? node.measured fallbacks in getNodeWidth, getNodeHeight and toStoredPositions read the enlarged size from it.

Example: at 150% text size, drag a node. The containers are fitted to the enlarged cards, and that layout is saved. All viewers who load it get containers sized for one viewer's text size.

Fix: on that path, remove measured from the cards too, or do not use the measured fallback for cards when the sizes are reflowed and saved. A test at a text scale other than 1 that checks the saved container sizes would keep this from coming back.

Worth including

  • The ExportButton and floating-edge test fixtures still use the v11 node shape (positionAbsolute, width and height on the node). So the tests run only the v11 fallback branches in nodeGeometry and diagramBounds. They pass because the fixture positions are already absolute, so a bug with child-node bounds would not be found. Please move the fixtures to the v12 shape (internals.positionAbsolute, measured).
  • After that, the v11 branches in nodeGeometry.ts are needed only for the old fixtures, as its header comment says. They can then be removed, so that the helpers read one node shape.
  • ArchitectureGraph.test.tsx and PatternGraph.test.tsx still mock default and __esModule. @xyflow/react has no default export, so these entries can go.

Minor (optional)

  • nodeGeometry reads measured before width, but getNodeWidth and toStoredPositions read width before measured. Using one order everywhere would make the size rules easier to follow.

Do not set width/height on custom nodes when restoring a layout, and
drop measured as well as width/height before a non-100% or presentation
save. Move geometry fixtures to the v12 node shape, remove the v11
fallbacks in nodeGeometry, and drop incidental CLI/calm-server lockfile
version bumps that would conflict with releases.
@Mittalnew

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I've stopped applyPositions from setting width/height on custom nodes, and the non-100%/presentation save path now drops measured as well as width/height so one viewer's text size isn't saved for everyone. There's a test at a text scale other than 1 that checks the saved container sizes. I also moved the geometry fixtures to the v12 shape, removed the v11 fallbacks in nodeGeometry, dropped the __esModule/default mock entries, and reverted the incidental CLI and calm-server version lines in package-lock.json.

@markscott-ms markscott-ms left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Mittalnew, the points from the first review are all addressed. One more change is necessary, and it comes from the fix for finding 1.

A new copy in a saved layout can overlap the card above it

Cards no longer get their stored size in applyPositions, but placeNewChildren still uses getNodeHeight(sibling) to put a new child (for example a new copy of a shared node) below its siblings. Without a stored height on the card, this is now the 100px default. The gap is 80px, so the new card overlaps any sibling card taller than 180px.

Example: a container with one card saved at y=80 with height 300, plus a new copy. On main the copy goes to y=460, below the card. On this branch it goes to y=260, inside the card, and the container does not grow to hold it.

Fix: in placeNewChildren, read a placed sibling's size from positionsById (the stored width and height) before you fall back to getNodeHeight/getNodeWidth. Please add a test with a tall stored card.

placeNewChildren now reads a placed sibling's width and height from
positionsById when the node has no size of its own, then falls back to
getNodeHeight/getNodeWidth, so a new copy is laid below a tall stored
card instead of overlapping it.
@Mittalnew

Copy link
Copy Markdown
Contributor Author

Thanks @markscott-ms, good catch. placeNewChildren now reads a placed sibling's width and height from positionsById when the node has no size of its own, then falls back to getNodeHeight/getNodeWidth, and I added a test with a tall stored card so a new copy is placed below it instead of overlapping.

@markscott-ms markscott-ms left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Mittalnew for this careful move to React Flow 12, and for the quick and thorough fixes to each review.

@markscott-ms
markscott-ms merged commit ee3b7ae into finos:main Nov 13, 2026
27 checks passed
@Mittalnew

Copy link
Copy Markdown
Contributor Author

Thanks @markscott-ms for the thorough reviews .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

calm-hub-ui Affects `calm-hub-ui` config

Projects

None yet

Development

Successfully merging this pull request may close these issues.

calm-hub-ui: React Flow warns about new nodeTypes on each diagram mount in development

2 participants