Skip to content

reacitivity broken when using classes #15663

@mithrendal

Description

@mithrendal

Describe the bug

state rune reactivity does not work when using an object which has been "newed" from an Java or Typescript class

<script>
    class MyJSclass {
       count = 0;
    }
    let jsclazz = $state(new MyJSclass());
</script>
    
counter { jsclazz.count } 
    
<button onclick={()=>jsclazz.count++}>increase</button>

when the rune declaration

    let jsclazz = $state(new MyJSclass());  

is changed to

    let jsclazz = $state({...new MyJSclass()});  

it works as expected.

Reproduction

<script>
    class MyJSclass {
      count = 0;
    }
    let jsclazz = $state(new MyJSclass());
</script>
    
counter { jsclazz.count } 
    
<button onclick={()=>jsclazz.count++}>increase</button>

Logs

System Info

any svelte5 system, online REPL or freshly scaffolded svelte5 app

Severity

annoyance

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