Skip to content

Commit

Permalink
better handling of solution data usage during wait for result
Browse files Browse the repository at this point in the history
  • Loading branch information
cdriesler committed Jul 23, 2023
1 parent 6b48ad5 commit 3bc0560
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import React, { useRef } from 'react'
import type * as NodePen from '@nodepen/core'
import type { NodePortReference } from '@/types'
import { useNodeAnchorPosition, usePortValues } from '@/hooks'
import { WirePortal, WiresMaskPortal } from './components'
Expand All @@ -19,19 +20,27 @@ const PortConnectionWire = ({ from, to }: PortConnectionWireProps): React.ReactE

const sourceDataTree = usePortValues(fromNodeId, fromPortId)

const previousStructure = useRef<NodePen.DataTreeStructure>('single')

if (!fromPosition || !toPosition) {
return null
}

const structure = sourceDataTree?.stats?.treeStructure ?? 'single'
const currentStructure = sourceDataTree?.stats?.treeStructure

if (currentStructure) {
previousStructure.current = currentStructure
}

const visibleStructure = currentStructure ?? previousStructure.current

return (
<>
<WirePortal>
<Wire start={fromPosition} end={toPosition} structure={structure} />
<Wire start={fromPosition} end={toPosition} structure={visibleStructure} />
</WirePortal>
<WiresMaskPortal>
<Wire start={fromPosition} end={toPosition} structure={structure} drawMask />
<Wire start={fromPosition} end={toPosition} structure={visibleStructure} drawMask />
</WiresMaskPortal>
</>
)
Expand Down
3 changes: 2 additions & 1 deletion packages/nodes/src/hooks/usePortValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const usePortValues = (nodeInstanceId: string, portInstanceId: string): N

// Cache value in store
useEffect(() => {
if (!value) {
if (!value || solutionStatus === 'expired') {
return
}

Expand All @@ -77,6 +77,7 @@ export const usePortValues = (nodeInstanceId: string, portInstanceId: string): N

if (!nodeSolutionData) {
console.log(`🐍 Attempted to cache results for node that does not exist: [${nodeInstanceId}]`)
console.log(value)
return
}

Expand Down

0 comments on commit 3bc0560

Please sign in to comment.