Skip to content

Commit 22cbe55

Browse files
committed
fixed remaining zustand warnings
1 parent 3275e9e commit 22cbe55

File tree

7 files changed

+25
-9
lines changed

7 files changed

+25
-9
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/combobox/combobox.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
22
import { isEqual } from 'lodash'
33
import { useReactFlow } from 'reactflow'
4+
import { useStoreWithEqualityFn } from 'zustand/traditional'
45
import { Combobox, type ComboboxOption } from '@/components/emcn/components'
56
import { cn } from '@/lib/core/utils/cn'
67
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
@@ -102,7 +103,8 @@ export const ComboBox = memo(function ComboBox({
102103
[blockConfig?.subBlocks]
103104
)
104105
const canonicalModeOverrides = blockState?.data?.canonicalModes
105-
const dependencyValues = useSubBlockStore(
106+
const dependencyValues = useStoreWithEqualityFn(
107+
useSubBlockStore,
106108
useCallback(
107109
(state) => {
108110
if (dependsOnFields.length === 0 || !activeWorkflowId) return []

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/dropdown/dropdown.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
22
import { isEqual } from 'lodash'
3+
import { useStoreWithEqualityFn } from 'zustand/traditional'
34
import { Badge } from '@/components/emcn'
45
import { Combobox, type ComboboxOption } from '@/components/emcn/components'
56
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
@@ -100,7 +101,8 @@ export const Dropdown = memo(function Dropdown({
100101
[blockConfig?.subBlocks]
101102
)
102103
const canonicalModeOverrides = blockState?.data?.canonicalModes
103-
const dependencyValues = useSubBlockStore(
104+
const dependencyValues = useStoreWithEqualityFn(
105+
useSubBlockStore,
104106
useCallback(
105107
(state) => {
106108
if (dependsOnFields.length === 0 || !activeWorkflowId) return []

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-depends-on-gate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useCallback, useMemo } from 'react'
44
import { isEqual } from 'lodash'
5+
import { useStoreWithEqualityFn } from 'zustand/traditional'
56
import {
67
buildCanonicalIndex,
78
isNonEmptyValue,
@@ -151,7 +152,7 @@ export function useDependsOnGate(
151152

152153
// Get values for all dependency fields (both all and any)
153154
// Use isEqual to prevent re-renders when dependency values haven't actually changed
154-
const dependencyValuesMap = useSubBlockStore(dependencySelector, isEqual)
155+
const dependencyValuesMap = useStoreWithEqualityFn(useSubBlockStore, dependencySelector, isEqual)
155156

156157
const depsSatisfied = useMemo(() => {
157158
// Check all fields (AND logic) - all must be satisfied

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef } from 'react'
22
import { createLogger } from '@sim/logger'
33
import { isEqual } from 'lodash'
44
import { useShallow } from 'zustand/react/shallow'
5+
import { useStoreWithEqualityFn } from 'zustand/traditional'
56
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
67
import { getProviderFromModel } from '@/providers/utils'
78
import { useWorkflowDiffStore } from '@/stores/workflow-diff/store'
@@ -58,7 +59,8 @@ export function useSubBlockValue<T = any>(
5859
const streamingValueRef = useRef<T | null>(null)
5960
const wasStreamingRef = useRef<boolean>(false)
6061

61-
const storeValue = useSubBlockStore(
62+
const storeValue = useStoreWithEqualityFn(
63+
useSubBlockStore,
6264
useCallback(
6365
(state) => {
6466
// If the active workflow ID isn't available yet, return undefined so we can fall back to initialValue
@@ -92,7 +94,8 @@ export function useSubBlockValue<T = any>(
9294

9395
// Always call this hook unconditionally - don't wrap it in a condition
9496
// Optimized: only re-render if model value actually changes
95-
const modelSubBlockValue = useSubBlockStore(
97+
const modelSubBlockValue = useStoreWithEqualityFn(
98+
useSubBlockStore,
9699
useCallback((state) => (blockId ? state.getValue(blockId, 'model') : null), [blockId]),
97100
(a, b) => a === b
98101
)

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/editor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
44
import { isEqual } from 'lodash'
55
import { BookOpen, Check, ChevronDown, ChevronUp, Pencil } from 'lucide-react'
66
import { useShallow } from 'zustand/react/shallow'
7+
import { useStoreWithEqualityFn } from 'zustand/traditional'
78
import { Button, Tooltip } from '@/components/emcn'
89
import {
910
buildCanonicalIndex,
@@ -99,7 +100,8 @@ export function Editor() {
99100
currentWorkflow.isSnapshotView
100101
)
101102

102-
const blockSubBlockValues = useSubBlockStore(
103+
const blockSubBlockValues = useStoreWithEqualityFn(
104+
useSubBlockStore,
103105
useCallback(
104106
(state) => {
105107
if (!activeWorkflowId || !currentBlockId) return EMPTY_SUBBLOCK_VALUES

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/workflow-block.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createLogger } from '@sim/logger'
33
import { isEqual } from 'lodash'
44
import { useParams } from 'next/navigation'
55
import { Handle, type NodeProps, Position, useUpdateNodeInternals } from 'reactflow'
6+
import { useStoreWithEqualityFn } from 'zustand/traditional'
67
import { Badge, Tooltip } from '@/components/emcn'
78
import { cn } from '@/lib/core/utils/cn'
89
import { getBaseUrl } from '@/lib/core/utils/urls'
@@ -526,7 +527,8 @@ const SubBlockRow = memo(function SubBlockRow({
526527
* Subscribe only to variables for this workflow to avoid re-renders from other workflows.
527528
* Uses isEqual for deep comparison since Object.fromEntries creates a new object each time.
528529
*/
529-
const workflowVariables = useVariablesStore(
530+
const workflowVariables = useStoreWithEqualityFn(
531+
useVariablesStore,
530532
useCallback(
531533
(state) => {
532534
if (!workflowId) return {}
@@ -729,7 +731,8 @@ export const WorkflowBlock = memo(function WorkflowBlock({
729731
const isStarterBlock = type === 'starter'
730732
const isWebhookTriggerBlock = type === 'webhook' || type === 'generic_webhook'
731733

732-
const blockSubBlockValues = useSubBlockStore(
734+
const blockSubBlockValues = useStoreWithEqualityFn(
735+
useSubBlockStore,
733736
useCallback(
734737
(state) => {
735738
if (!activeWorkflowId) return EMPTY_SUBBLOCK_VALUES

apps/sim/app/workspace/[workspaceId]/w/components/preview/preview.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ export function WorkflowPreview({
215215
executedBlocks,
216216
selectedBlockId,
217217
}: WorkflowPreviewProps) {
218-
const nodeTypes = lightweight ? lightweightNodeTypes : fullNodeTypes
218+
const nodeTypes = useMemo(
219+
() => (lightweight ? lightweightNodeTypes : fullNodeTypes),
220+
[lightweight]
221+
)
219222
const isValidWorkflowState = workflowState?.blocks && workflowState.edges
220223

221224
const blocksStructure = useMemo(() => {

0 commit comments

Comments
 (0)