Skip to content

refactor(core): trim per-instance setup in Node/EdgeWrapper#2160

Merged
bcakmakoglu merged 3 commits into
release/2.0.0from
refactor/drop-element-hooks
Jun 19, 2026
Merged

refactor(core): trim per-instance setup in Node/EdgeWrapper#2160
bcakmakoglu merged 3 commits into
release/2.0.0from
refactor/drop-element-hooks

Conversation

@bcakmakoglu

@bcakmakoglu bcakmakoglu commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Two related per-instance trims in the element wrappers — identical dispatch/behavior, less allocated per node/edge on the mount path.

1. Drop the per-wrapper useNodeHooks / useEdgeHooks

These internal composables created, per NodeWrapper/EdgeWrapper instance, a second set of 9 ExtendedEventHooks whose only .on listener forwarded to the global emits hooks — then handed the triggers back as emit. So emit.click(x) was just emits.nodeClick(x) with an extra hop.

The canonical hub is the global hook set in store/hooks.ts (these back both onNodeClick/onEdgeClick and the Vue @node-click emitter via useHooks); the per-wrapper layer had no other subscribers.

  • NodeWrapper/EdgeWrapper call emits.node*/emits.edge* (and unprefixed emits.reconnect*) directly.
  • Deleted useNodeHooks.ts/useEdgeHooks.ts + their composables/index.ts exports.
  • Removed the now-unused NodeEventsEmit/EdgeEventsEmit types (*EventsOn/*EventsHandler stay — they back the public on* API).

Drops 9 hook instances + 9 forwarding closures per node and per edge.

2. NodeWrapper resolves its node via a direct computed

NodeWrapper used the public useNode composable but only ever read its node. It now resolves the InternalNode with computed(() => getInternalNode(id)) (identical to useNode().node), dropping the unused parentNode/connectedEdges computeds, the nodeEl inject, and a redundant useVueFlow/useStore resolution that useNode allocated per node. useNode is unchanged for custom-node use. (EdgeWrapper already resolved its edge this way.)

Why

Both are zero behavioral change — same dispatch, same node resolution — but trim per-instance setup cost + retained memory. No public runtime API change (the hooks were @internal; useNode stays public).

Tests

Full interaction suite green (21/21): drag (nodeDragStart/Drag/Stop), connect, looseReconnect (reconnect*), selectionClickVsDrag, vmodel, basic (click/mouse), onBeforeDelete, edgeZIndex.

🤖 Generated with Claude Code

These internal composables created a second set of 9 ExtendedEventHooks per
node and per edge whose only listener forwarded to the global `emits` hooks.
NodeWrapper/EdgeWrapper now call emits.node*/emits.edge* directly — identical
dispatch (the global hooks in store/hooks.ts back both the on* subscriptions
and the Vue @event emitter), minus 9 hook instances + 9 forwarding closures
of setup cost and memory per element. Drops the now-unused NodeEventsEmit/
EdgeEventsEmit types.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codesandbox

codesandbox Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot

changeset-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3df3093

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@vue-flow/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

NodeWrapper used the public `useNode` composable but only ever read its
`node`. Resolve the InternalNode with `computed(() => getInternalNode(id))`
directly — identical to useNode's `node` — dropping the unused
parentNode/connectedEdges computeds, the nodeEl inject, and a redundant
useVueFlow/useStore resolution that useNode allocated per node. `useNode`
stays unchanged for custom-node use.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bcakmakoglu bcakmakoglu changed the title refactor(core): drop the per-wrapper useNodeHooks/useEdgeHooks refactor(core): trim per-instance setup in Node/EdgeWrapper Jun 19, 2026
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
@bcakmakoglu bcakmakoglu self-assigned this Jun 19, 2026
@bcakmakoglu bcakmakoglu added the refactor Refactor existing features label Jun 19, 2026
@bcakmakoglu
bcakmakoglu merged commit f3e9a2c into release/2.0.0 Jun 19, 2026
2 checks passed
@bcakmakoglu
bcakmakoglu deleted the refactor/drop-element-hooks branch June 19, 2026 06:28
@bcakmakoglu
bcakmakoglu restored the refactor/drop-element-hooks branch June 19, 2026 06:36
@bcakmakoglu
bcakmakoglu deleted the refactor/drop-element-hooks branch June 19, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactor existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant