Skip to content

onDestroy callbacks are not called during SSR #10296

@Rich-Harris

Description

@Rich-Harris

Describe the bug

main-server.js re-exports onDestroy from main-client.js. This is wrong. That function looks like this:

export function onDestroy(fn) {
  if (!is_ssr) {
    user_effect(() => () => untrack(fn));
  }
}

Instead, we should export a server-side onDestroy directly from main-server.js, and it should run destroy callbacks once SSR is complete.

I also noticed that we're re-exporting createEventDispatcher, when that should (I think?) just be a no-op in SSR like onMount and friends.

Reproduction

In lieu of a repro I'll open a PR with a failing test

Logs

No response

System Info

next

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions