Skip to content

onMount ignored in class constructors #14042

@tBuLi12

Description

@tBuLi12

Describe the bug

For a svelte 5 component with runes disabled, onMount is ignored when called inside the constructor of a class that's defined outside a svelte component and constructed inside the component during initialization, provided that this is the only onMount callback registered.

Interestingly enough, this issue does not occur when using a function instead of a class constructor.

Reproduction

https://svelte.dev/playground/hello-world?version=5.1.4#H4sIAAAAAAAACnWQy26DMBBFf8WdFUgRqFtKkapuuskX1FlQmKRU9hjZk5eQ_712HEqR2gWbw52ZezwBtRqhgjdUyoizsaoXGfYDY5_DBvaDQgfV-wR8HWMugsDvUy_jWLgTKo7so3X4F-8MMRKHNVC7zg4jN5IkD3o0lsUkttdX1TonvNhbo4WEotQJFV9OwlMMx4_wPGezPNC6XLZR_fnYJIcpdvAPdRmIpHCf8cJQsT2i3_zjsdxbe6z4L4-f7oa25ki8dE_WqTXh5Rbrbnqz5hRdwi4XGnVsbJYnlKBRWChzyCRYPAyO0c43JOTpKfgOsjD53Ij1lI5_sA_hlPaS_PoNdv4bLxC8WvUBAAA=

In the REPL above after the component has mounted "register onMount" is visible, but "mounted" is not.

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-1260P
    Memory: 16.65 GB / 31.70 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
    bun: 1.1.1 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    svelte: ^5.1.0 => 5.1.0

Severity

annoyance

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions