Skip to content

Conversation

benceruleanlu
Copy link
Member

@benceruleanlu benceruleanlu commented Sep 6, 2025

Summary

Fixed Vue's auto-unwrapping behavior for exposed template refs in slot components, resolving slot registration failures.

Changes

  • What: Corrected type and access pattern for component refs exposed via defineExpose in InputSlot.vue and OutputSlot.vue
  • Breaking: None
  • Dependencies: None

Review Focus

The key fix addresses Vue's automatic ref unwrapping when a child component exposes a ref through defineExpose. The parent was incorrectly treating the exposed value as a Ref<HTMLElement> and calling .value, but Vue already unwraps it to HTMLElement.

Technical Details

Exact Issue

  • Child component SlotConnectionDot.vue exposes a template ref with defineExpose({ slotElRef }), where slotElRef comes from useTemplateRef('slot-el')
  • When a child exposes a Ref via defineExpose, Vue auto-unwraps it on the parent component instance proxy
  • Previously, the parent treated it as Ref and read .value (double-unwrapping), which produced undefined at runtime
  • Result: slotElRef stayed null and useDomSlotRegistration had no element to measure/register, breaking slot hit-testing/linking

What Changed

Before:

  • connectionDotRef: ref<{ slotElRef: Ref<HTMLElement> }>()
  • Used watch(connectionDotRef, ...) and accessed newValue.slotElRef.value

After:

  • connectionDotRef: ref<ComponentPublicInstance<{ slotElRef: HTMLElement | undefined }> | null>()
  • Used watchEffect(() => { slotElRef.value = connectionDotRef.value?.slotElRef || null })

Why It Works

  1. Auto-unwrapping: Stopped calling .value on an already unwrapped HTMLElement
  2. Timing: watchEffect reruns when the child's exposed slotElRef appears (after mount), whereas the old watch only reacted to component ref assignment

With these fixes, slotElRef is reliably populated, useDomSlotRegistration can measure and register slot positions, and slot hit-testing/connection logic works as intended.

┆Issue is synchronized with this Notion page by Unito

Fixed the misuse of exposed template refs in InputSlot and OutputSlot components.
When Vue exposes a Ref via defineExpose, it auto-unwraps it on the parent
component instance. The previous code was incorrectly double-unwrapping by
calling .value on an already unwrapped HTMLElement.

Changes:
- Updated type to ComponentPublicInstance with unwrapped HTMLElement
- Replaced watch with watchEffect for better timing handling
- Removed incorrect .value access on auto-unwrapped ref

This ensures slot elements are properly registered with useDomSlotRegistration,
fixing slot position tracking and hit-testing in the layout system.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@benceruleanlu benceruleanlu requested a review from a team as a code owner September 6, 2025 05:55
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 6, 2025
Copy link

github-actions bot commented Sep 6, 2025

🎭 Playwright Test Results

All tests passed across all browsers!

⏰ Completed at: 09/06/2025, 06:05:26 AM UTC

📊 Test Reports by Browser


🎉 Your tests are passing across all browsers!

@benceruleanlu
Copy link
Member Author

This is one of like three issues blocking link rendering from depending on the layout tree properly

@christian-byrne christian-byrne merged commit 8445605 into main Sep 6, 2025
23 checks passed
@christian-byrne christian-byrne deleted the fix/slot-ref-unwrapping branch September 6, 2025 10:37
@benceruleanlu benceruleanlu mentioned this pull request Sep 7, 2025
snomiao pushed a commit that referenced this pull request Sep 12, 2025
Fixed the misuse of exposed template refs in InputSlot and OutputSlot components.
When Vue exposes a Ref via defineExpose, it auto-unwraps it on the parent
component instance. The previous code was incorrectly double-unwrapping by
calling .value on an already unwrapped HTMLElement.

Changes:
- Updated type to ComponentPublicInstance with unwrapped HTMLElement
- Replaced watch with watchEffect for better timing handling
- Removed incorrect .value access on auto-unwrapped ref

This ensures slot elements are properly registered with useDomSlotRegistration,
fixing slot position tracking and hit-testing in the layout system.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants