Skip to content

Props default values should behave like default arguments of functions #4442

@mindrones

Description

@mindrones

Describe the bug

When a prop has a default value, if you instantiate the component without that prop and then update that prop with a value and then update the component again without that prop, the prop does not take the default value anymore.

This has been discussed in #support today around 7pm.
These issues have been mentioned: #1467, #3251
Another similar issue: #3063

Logs

N/A

To Reproduce

This is intuitive but it doesn't work as I expect it: https://svelte.dev/repl/f7121f1c22c7467985b2a761dc310aea?version=3.18.2.

This is how you get it to work but it's counter intuitive to me: https://svelte.dev/repl/8ab3b1414ee54d00b24dbd66dafed5b3?version=3.18.2

Expected behavior

I think props default values should behave like default arguments of a function: if the passed prop is undefined the component should assign the default value no matter what.

Stacktraces

N/A

Information about your Svelte project:

N/A

Severity

I would say annoying/counter intuitive, especially because the doc says [1]:

You can specify a default value, which will be used if the component's consumer doesn't specify a prop.

so this can be pretty puzzling at first.

[1] https://svelte.dev/docs#1_export_creates_a_component_prop

Additional context

N/A

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