Skip to content

Commit

Permalink
Merge pull request #2233 from stakwork/bugfix/black-screen-fix
Browse files Browse the repository at this point in the history
feat: add try catch, additional check for incorrect links
  • Loading branch information
Rassl authored Sep 25, 2024
2 parents 9fc43d7 + 213d2bc commit a681604
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/stores/useGraphStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,31 @@ export const useGraphStore = create<GraphStore>()((set, get) => ({
nodes.push(...structuredNodes)
links.push(...structuredLinks)

simulation.nodes(nodes).force('link').links(links)
try {
simulation.nodes(nodes)

const filteredLinks = links.filter((link: Link<NodeExtended | string>) => {
const { target, source } = link
const simulationNodes = simulation.nodes()

// Log the target and source ref_id for debugging
const targetRefId = (target as NodeExtended)?.ref_id || target
const sourceRefId = (source as NodeExtended)?.ref_id || source

return (
simulationNodes.some((n: NodeExtended) => n.ref_id === targetRefId) &&
simulationNodes.some((n: NodeExtended) => n.ref_id === sourceRefId)
)
})

simulation.force('link').links([]).links(filteredLinks)

simulationHelpers.simulationRestart()
} catch (error) {
console.log(error)
// eslint-disable-next-line no-debugger
}

simulationHelpers.simulationRestart()
// Add simulation node to reference (so that we can access reference on tick to update position)
},

Expand Down Expand Up @@ -280,6 +302,8 @@ export const useGraphStore = create<GraphStore>()((set, get) => ({
},
},
simulationCreate: (nodes, links) => {
console.log('created')

const structuredNodes = structuredClone(nodes)
const structuredLinks = structuredClone(links)

Expand Down

0 comments on commit a681604

Please sign in to comment.