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

{#if a.deep != null} runs when a.deep is null if used as a transition parameter #15627

Open
rChaoz opened this issue Mar 27, 2025 · 0 comments
Open

Comments

@rChaoz
Copy link
Contributor

rChaoz commented Mar 27, 2025

Describe the bug

Did my best with the title. Can't describe this very well, please see the reproduction as I almost died getting it.

In short, this code...

{#if s.drawer}
  {s.drawer.toString()}
{/if}

...crashes with s.drawer is undefined. The contents of the if are evaluated even when the if is false, but only when s.drawer is used as the argument of a transition (transition:whatever={s.drawer}).

Reproduction

REPL

<script>
	const s = $state({})
	
	function slide() {
			return { duration: 150 }
	}
	
	function open() {
		s.drawer = { id: 123 }
	}
	
	function close() {
		delete s.drawer
	}
</script>

Hit Open, then Close. It crashes and the drawer remains open but the Close
button cannot be interacted with anymore (see console).
<br><br>

{#if s.drawer}
    {@const id = s.drawer.id}
    {#if id}
	Hi, I'm the drawer.
	<!-- Remove the "={id}" and the error goes away -->
        <button transition:slide|global onclick={close}>Close</button>
    {/if}
{/if}

<button onclick={open}>Open</button>

Regression

This is also a regression. The same bug happens in legacy mode, but the code works in v4.

v5 REPL | v4 REPL

Severity

annoyance

@rChaoz rChaoz changed the title {#if a.deep != null} executes even when a.deep is null if it's used as the parameter of a transition {#if a.deep != null} runs when a.deep is null if used as a transition parameter Mar 27, 2025
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

1 participant