Skip to content

fix(runtime-vapor): distinguish omitted and empty class in dynamic bindings - #16425

Closed
linzch3 wants to merge 1 commit into
vuejs:minorfrom
linzch3:fix/vapor-svg-dynamic-class
Closed

linzch3 wants to merge 1 commit into
vuejs:minorfrom
linzch3:fix/vapor-svg-dynamic-class

Conversation

@linzch3

@linzch3 linzch3 commented Nov 23, 2026

Copy link
Copy Markdown

Fixes #16422

Summary

With object-form v-bind on an SVG element (both root and nested), Vapor previously conflated an omitted/null class binding with an explicitly empty class: '' binding:

  • Setting { class: '' } left getAttribute('class') as null (skipped in setClassIncremental because '' is falsy, and skipped on non-root elements because Element.prototype.$cls defaulted to '').
  • Omitting class after { class: 'active' } normalized null to '' and left class="" behind instead of removing the attribute like VDOM.

Fix

  • Preserve null (omitted/nullish) separately from '' (explicitly empty) in setClass and setClassIncremental.
  • Initialize Element.prototype.$cls to undefined so an initial class: '' write is not skipped.
  • On non-root elements, call el.removeAttribute('class') when value == null.
  • In setClassIncremental, when el.classList.length === 0, write el.setAttribute('class', '') for explicit '' and call el.removeAttribute('class') for null unless the other layer or template retains an empty class attribute.
  • Updated the existing assertion in interopSlots.spec.ts where clearing cloned attrs to {} now matches VDOM (<button id="x">close</button>).

Testing

  • Added renderParity regression tests in packages/runtime-vapor/__tests__/dom/svg.spec.ts covering root and nested <svg v-bind="attrs" /> across omitted, empty, active, and null transitions.
  • Verified both tests fail without the fix with the [Vapor] Object v-bind on an SVG root conflates omitted and explicitly empty class #16422 mismatch and pass with it.
  • Ran vp test run --project 'unit*' packages/runtime-vapor (77 files, 4535 passing), tsc --noEmit, and vp check.

…ndings

Signed-off-by: linzch3 <linzch3@outlook.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 630f80fb-768a-46d4-a566-fb135c0d47c0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@linzch3 linzch3 closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant