Fix NetworkModificationTree: Manage tree fitView at initialization#3819
Fix NetworkModificationTree: Manage tree fitView at initialization#3819
Conversation
Signed-off-by: sBouzols <sylvain.bouzols@gmail.com>
Mathieu-Deharbe
left a comment
There was a problem hiding this comment.
OK, bug corrected.
There is a slight "jump->zoom" when a large tree is loaded. First it is zoomed in for about half a second and then fitViewed. Maybe a loader will have to be added or simply hide the tree until the end of the loading.
📝 WalkthroughWalkthroughThe Changes
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can enforce grammar and style rules using `languagetool`.Configure the |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/components/network-modification-tree.jsx (1)
288-294: Consider wrappingonReactFlowInitinuseCallbackfor consistency.All other event handlers in this component are memoized with
useCallback. While the impact is minimal sinceonInitfires only once, memoizing this handler maintains consistency and prevents unnecessary reference changes that could trigger re-renders of the ReactFlow component.♻️ Suggested refactor
- // FIX : when fitting the view, the nodes are not yet rendered, so the view is not correctly - // centered and zoomed on the nodes. We need to wait for the nodes to be rendered and then fit the view. - // cf https://github.com/xyflow/xyflow/issues/533 - const onReactFlowInit = (rf) => { - rf.fitView(); - }; - // END OF FIX + // FIX : when fitting the view, the nodes are not yet rendered, so the view is not correctly + // centered and zoomed on the nodes. We need to wait for the nodes to be rendered and then fit the view. + // cf https://github.com/xyflow/xyflow/issues/533 + const onReactFlowInit = useCallback((rf) => { + rf.fitView(); + }, []); + // END OF FIX🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/network-modification-tree.jsx` around lines 288 - 294, Wrap the onReactFlowInit handler in useCallback to memoize it like the other handlers: replace the plain function const onReactFlowInit = (rf) => { rf.fitView(); } with a useCallback version (e.g., const onReactFlowInit = useCallback((rf) => { rf.fitView(); }, [])), and ensure useCallback is imported from React if not already; keep an empty dependency array since the handler only needs to run once on init.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/components/network-modification-tree.jsx`:
- Around line 288-294: Wrap the onReactFlowInit handler in useCallback to
memoize it like the other handlers: replace the plain function const
onReactFlowInit = (rf) => { rf.fitView(); } with a useCallback version (e.g.,
const onReactFlowInit = useCallback((rf) => { rf.fitView(); }, [])), and ensure
useCallback is imported from React if not already; keep an empty dependency
array since the handler only needs to run once on init.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 11319195-9465-4952-90ff-f3ad6093d420
📒 Files selected for processing (1)
src/components/network-modification-tree.jsx



PR Summary
current behaviour :
fitViewseems not executed at init of theReactFlowcomponentnext behaviour :
fitViewis executed at init.see xyflow/xyflow#533 for this kind of issue recommended fix