Skip to content

class:directive not working with $$restProps #15386

Closed
@metonym

Description

@metonym

Describe the bug

I'm experiencing this bug with Svelte versions 5.20.3 and 5.20.4.

If I have a component that uses a class: directive to toggle a class and also spread $$restProps to it, the class: directive is not updated.

<!-- `class:active` is not updated if spreading $$restProps -->
<div class:active={active} {...$$restProps}>

<!-- The markup is correctly updated if `active` changes -->
  <slot /> {active}
</div>

In the provided repro, do the following:

  1. Click the "Toggle" button
  2. The active prop passed to the Component should turn it blue
  3. Click "Toggle" again
  4. The {active} updates in the slot, but the class directive is not updated

Now remove the $$restProps from the Component; it works as expected. The expected behavior is that the class: directive should still re-compute with $$restProps being spread.

From what I can tell, this was working with early patches of 5.20.

Based on the changelog of 5.20.3, I wonder if this could be related to the issue?

fix: correctly override class attributes with class directives

For additional context, I stumbled upon this when investigating this issue for Carbon Svelte: carbon-design-system/carbon-components-svelte#2102

Reproduction

https://svelte.dev/playground/e7cf33de70ae4059a5c99bb3b6c8fefa?version=5.20.4

Logs

System Info

System:
  OS: macOS 13.5.2
  CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
  Memory: 185.26 MB / 16.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
  npm: 9.9.3 - ~/.nvm/versions/node/v20.11.1/bin/npm
  pnpm: 9.15.0 - ~/Library/pnpm/pnpm
  bun: 1.2.3 - ~/.bun/bin/bun
Browsers:
  Chrome: 133.0.6943.127
  Safari: 16.6
npmPackages:
  svelte: 5.20.4 => 5.20.4

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions