Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind:this produces unwanted read of $props during unmount #14980

Open
x0k opened this issue Jan 11, 2025 · 3 comments
Open

bind:this produces unwanted read of $props during unmount #14980

x0k opened this issue Jan 11, 2025 · 3 comments

Comments

@x0k
Copy link

x0k commented Jan 11, 2025

Describe the bug

reproduction: click on Del button to get an error in console
expected: no error

Current behavior is understandable from reactive system point of view, but I was very surprised as a consumer of a library that uses code like in the Input.svelte component.

Reproduction

REPL

Logs

No response

System Info

System:
    OS: Linux 6.6 cpe:/o:nixos:nixos:24.11 24.11 (Vicuna)
    CPU: (12) x64 Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz
    Memory: 8.79 GB / 15.56 GB
    Container: Yes
    Shell: 5.9 - /run/current-system/sw/bin/zsh
  Binaries:
    Node: 22.10.0 - /nix/store/hnkyz55vndmvwhg6nzpliv86gh6sxg7h-nodejs-22.10.0/bin/node
    npm: 10.9.0 - /nix/store/hnkyz55vndmvwhg6nzpliv86gh6sxg7h-nodejs-22.10.0/bin/npm
    pnpm: 9.15.3 - /nix/store/by7hqplbckljzzsq6jpmcjp1w4jzvxpg-pnpm-9.15.3/bin/pnpm
  Browsers:
    Brave Browser: 131.1.73.104

Severity

annoyance

@Leonidaz
Copy link

It looks like it happens with a props spread.

Without the spread, everything works as expected. Optional chaining in the derived also solves this.

example without attribute spread

with spread compiles to:

	Input($$anchor, $.spread_props(() => $.get(attributes), {
		get value() {
			return value().value;
		},
		set value($$value) {
			value(value().value = $$value, true);
		}
	}));

without spread:

	Input($$anchor, {
		get title() {
			return $.get(attributes).title;
		},
		get value() {
			return value().value;
		},
		set value($$value) {
			value(value().value = $$value, true);
		}
	});

@x0k
Copy link
Author

x0k commented Jan 14, 2025

Thanks for the reply.
Unfortunately, this workaround is not suitable for my case:

  • I can't avoid the spread operation (I get an object with attributes from the user and mix them with the default attributes).
  • Optional chaining cannot be used in this case bind:value={object[property]}

@Leonidaz
Copy link

@trueadm it seems that it's inconsistent behavior where a component that is being unmounted behaves differently causing an error if a spread is used vs no spread when props become undefined. wonder if this can be fixed? The issue happens inside the Item.svelte when spreading {...attributes} vs explicitly specifying when App.svelte sets signal state to undefined (used both for {#if} and props).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants