Skip to content

State in onblur handler is undefined after navigation #16875

@MathiasWP

Description

@MathiasWP

Describe the bug

Relevant issues:

Relevant fixes:

I'm not really sure what the correct "mental model" is of this behaviour - but my two cents is that it feels wrong. It's really difficult to spot, as there's no typing that tells me that this can happen. The type-definition of let { data } = $props() is:

let data: {
    state: {
        message: string;
    };
}

How can one know that state can be undefined from this.

Reproduction

Github repro: https://github.com/MathiasWP/sveltekit-input-onblur-async-state-bug

Video:
https://github.com/user-attachments/assets/278db046-f4ec-4463-8b1c-c0158dbb23f3

Logs

+page.svelte?t=1759308998689:23 Uncaught TypeError: Cannot set properties of undefined (setting 'message')
    at HTMLInputElement.<anonymous> (+page.svelte?t=1759308998689:23:93)
    at events.js:61:21
    at without_reactive_context (shared.js:44:10)
    at HTMLInputElement.target_handler (events.js:60:11)
    at remove_effect_dom (effects.js:524:8)
    at destroy_effect (effects.js:471:3)
    at destroy_effect_children (effects.js:435:4)
    at destroy_effect (effects.js:475:2)
    at destroy_effect_children (effects.js:435:4)
    at destroy_effect (effects.js:475:2)

System Info

System:
    OS: macOS 15.6.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 274.14 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
    pnpm: 10.6.5 - /opt/homebrew/bin/pnpm
    bun: 1.0.0 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 139.1.81.137
    Chrome: 140.0.7339.208
    Edge: 140.0.3485.94
    Safari: 18.6
  npmPackages:
    svelte: ^5.0.0 => 5.39.7

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