Skip to content

fix: release removed node in single-mode slot controller - #13158

Merged
web-padawan merged 4 commits into
mainfrom
fix/slot-controller-teardown
Oct 19, 2026
Merged

web-padawan merged 4 commits into
mainfrom
fix/slot-controller-teardown

Conversation

@web-padawan

Copy link
Copy Markdown
Member

Description

Related to #13157

In single mode, SlotController kept a removed slotted node as node. Adding the same node back was then ignored, and SlotChildObserveController.teardownNode() passed the removed custom node to updateDefaultNode(), which overwrote its content.

  • Changed SlotController to reset node to null in single mode when the current node is removed
    • nodes is no longer set in single mode
  • Fixed custom slot="label" and slot="helper" content being cleared on removal when label / helperText is empty
    • Same for Details summary, Login title and Card title
  • Fixed a slotted node that is removed and added again being ignored, e.g. vaadin-tooltip (no has-tooltip, no target) and TabSheet vaadin-tabs
  • Added optional chaining to checkbox _labelNode and crud _headerNode reads, which can now be null
  • Added SlotController, TooltipController and LabelMixin tests

Type of change

  • Bugfix

How to test

  1. Open dev/text-field.html
  2. In DevTools, add <label slot="label">Custom</label> to a vaadin-text-field without label
  3. Remove the label element and check its textContent
  4. It should still be Custom, not empty

🤖 Generated with Claude Code

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 1 comment and collected 1 finding below that could not be attached to the diff.

Finding
📝 TypeScript definitions still declare node and _labelNode as non-nullable
🧪 New _labelNode null paths in checkbox have no test

📝 TypeScript definitions still declare node and _labelNode as non-nullable
SlotController.node is typed HTMLElement, and LabelMixin._labelNode (packages/field-base/src/label-mixin.d.ts:20) as HTMLLabelElement. Both can now be null — the JS side of this PR acknowledges that by adding ?. in checkbox and crud. TS consumers (including Flow components and anyone subclassing SlotController) get no warning for controller.node.textContent after the slotted node is removed.
slot-controller.d.ts:17 · documentation

target === this.inputElement ||
target.part.contains('required-indicator') ||
(this._labelNode.contains(target) && !target.closest('a'));
(this._labelNode?.contains(target) && !target.closest('a'));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 New _labelNode null paths in checkbox have no test

Removing a custom <label slot="label"> from a checkbox with no label property now leaves _labelNode as null permanently, since restoreDefaultNode only attaches a default when label is non-empty. Without the ?. in _shouldSetActive, every pointerdown on that checkbox throws. Nothing in packages/checkbox/test removes the slotted label, so dropping either guard later would go unnoticed.

vaadin-checkbox-mixin.js:134 · tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test to verify the clicking helper node after removing custom label does not throw.

web-padawan and others added 3 commits October 16, 2026 14:47
In single mode, removing the slotted node kept it as `node`, so adding
the same node back was ignored and teardown wrote default content into
the removed custom node. Guard checkbox and crud reads of the now
nullable node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@web-padawan
web-padawan force-pushed the fix/slot-controller-teardown branch from 5161810 to c5c1ec5 Compare October 16, 2026 11:47
@web-padawan

Copy link
Copy Markdown
Member Author

TypeScript definitions still declare node and _labelNode as non-nullable

Updated typings accordingly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@web-padawan
web-padawan removed the request for review from vursen October 19, 2026 11:49
@web-padawan
web-padawan merged commit eb80470 into main Oct 19, 2026
19 checks passed
@web-padawan
web-padawan deleted the fix/slot-controller-teardown branch October 19, 2026 11:49
web-padawan added a commit that referenced this pull request Oct 19, 2026
…3179)

Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 25.4.0-alpha4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants