perf(web): avoid unnecessary re-renders from Zustand setter subscriptions #21729

Closed
opened 2026-02-21 20:14:03 -05:00 by yindo · 1 comment
Owner

Originally created by @lyzno1 on GitHub (Jan 17, 2026).

Problem

Components subscribe to Zustand setter functions via useStore(s => s.setXxx) but only use them in callbacks. This causes unnecessary re-render checks when store changes.

Solution

Use store.getState().setXxx() in callbacks instead of subscribing to setters.

Originally created by @lyzno1 on GitHub (Jan 17, 2026). ## Problem Components subscribe to Zustand setter functions via `useStore(s => s.setXxx)` but only use them in callbacks. This causes unnecessary re-render checks when store changes. ## Solution Use `store.getState().setXxx()` in callbacks instead of subscribing to setters.
yindo added the 💪 enhancement label 2026-02-21 20:14:03 -05:00
yindo closed this issue 2026-02-21 20:14:03 -05:00
Author
Owner

@lyzno1 commented on GitHub (Jan 17, 2026):

This improvement is unnecessary for setters; it's at most a personal engineering fastidiousness. I will open a new PR to fix the real problem: for properties that are not used by the component but are used in certain functions, they should not be obtained using selectors, but rather the corresponding "snapshot" should be obtained using getState() in the callback function.

@lyzno1 commented on GitHub (Jan 17, 2026): This improvement is unnecessary for setters; it's at most a personal engineering fastidiousness. I will open a new PR to fix the real problem: for properties that are not used by the component but are used in certain functions, they should not be obtained using selectors, but rather the corresponding "snapshot" should be obtained using getState() in the callback function.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21729