Skip to content

#if goes to :else even if condition evaluates to true #4318

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

Closed
lud opened this issue Jan 25, 2020 · 8 comments
Closed

#if goes to :else even if condition evaluates to true #4318

lud opened this issue Jan 25, 2020 · 8 comments

Comments

@lud
Copy link

lud commented Jan 25, 2020

[email protected]

Hi,

I have this code

{#if !isOwner}
  {#if joined || !$ps.player_ids.includes(user.id)}
    true == {(joined || !$ps.player_ids.includes(user.id))}
  {:else}
    false == {(joined || !$ps.player_ids.includes(user.id))}
  {/if}
  
  ** skip **
{/if}

The result is

true == true

But if I write this instead:

{#if !isOwner}
  {#if joined || !$ps.player_ids.includes(user.id)}
    true == {(joined || !$ps.player_ids.includes(user.id))}
  {:else}
    false == {(joined || !$ps.player_ids.includes(user.id))}
    <div class="gbox">
      <!-- @lang -->
      <LoadMsg>Get ready</LoadMsg>
    </div>
  {/if}
 ** skip **
{/if}

Then the result will be

false == true
 Get ready

I do not know where to start to debug this. I think it may be a bug.

@lud
Copy link
Author

lud commented Jan 25, 2020

If I replace the LoadMsg with a div it works as intended.

This is the source code for LoadMsg :

<script>
  export let center = true
  export let inline = false
</script>

<style>
  p.center {
    text-align: center;
  }
</style>

{#if inline}
    <span class:text-center={center}>
      <i class="icon-spin spin"></i>
      <slot />
    </span>
{:else}
    <div class:text-center={center}>
      <i class="icon-spin spin"></i>
      <slot />
    </div>
{/if}

@Conduitry
Copy link
Member

Can you save a complete reproduction in the REPL and link to it?

@lud
Copy link
Author

lud commented Jan 25, 2020

Unfortunately not. It works as expected in the repl.

I wrote my code in another way, splitting the :else section in another if, and matching on another variable than joined, so I have a workaround, but still it should not be possible to display false == true !

@Conduitry Conduitry added the awaiting submitter needs a reproduction, or clarification label Jan 25, 2020
@ghost
Copy link

ghost commented Jan 26, 2020

I believe this is the same behavior as seen in #4263 with perhaps a different repro.

@lud lud changed the title #if goes to :else event if condition evaluates to true #if goes to :else even if condition evaluates to true Jan 26, 2020
@lud
Copy link
Author

lud commented Jan 26, 2020

Yes my store value has methods and it seems the tracking of values is lost when I add a custom component in the else section.

@antony
Copy link
Member

antony commented Jun 11, 2020

I can confirm I've seen this, but am also unable to reproduce it. I've ended up just writing the code in a different way.

I call it Schrodinger's variable. The store value is false outside an if, but if you log it inside the if, it is true. It's a tough one to track down.

@dummdidumm
Copy link
Member

closing as outdated and without repro

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Jan 19, 2024
@lud
Copy link
Author

lud commented Jan 24, 2024

Yep !

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

No branches or pull requests

6 participants