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} inside {#await} doesn't work #4044

Closed
ghost opened this issue Dec 3, 2019 · 6 comments · Fixed by #4065
Closed

{#if} inside {#await} doesn't work #4044

ghost opened this issue Dec 3, 2019 · 6 comments · Fixed by #4065
Labels

Comments

@ghost
Copy link

ghost commented Dec 3, 2019

Describe the bug
Having an {#if} inside of an {#await} using a resolved object from {:then} fails.

Logs
ReferenceError: object is not defined

To Reproduce

https://svelte.dev/repl/a5419c05b3314b83b75ce786562f2c06?version=3.16.0

Expected behavior
it should render the if block

Information about your Svelte project:

  • Firefox 70.0.1

  • Manjaro GNU/Linux

  • 3.16.0

Severity
It is blocking my app from upgrading.

@antony
Copy link
Member

antony commented Dec 3, 2019

Looks like it isn't using ctx in the generated if block, but instead is using literally the variable r

// (16:0) {:then r}
function create_then_block(ctx) {
	let if_block_anchor;
	let if_block = r.length < 1 && create_if_block(ctx);

@Conduitry Conduitry added the bug label Dec 3, 2019
@ghost
Copy link
Author

ghost commented Dec 3, 2019

That's what I saw. I tried doing stuff like [...r] or (r) but it won't work. Any idea?

Conduitry added a commit to Conduitry/svelte that referenced this issue Dec 3, 2019
Conduitry added a commit to Conduitry/svelte that referenced this issue Dec 3, 2019
Conduitry added a commit to Conduitry/svelte that referenced this issue Dec 3, 2019
@Conduitry
Copy link
Member

Something like this:

<script>
	let foo = [false, true];
</script>

{#each foo as bar}
	{#if bar}
		<p>true</p>
	{:else}
		<p>false</p>
	{/if}
{/each}

is getting handled correctly. So whatever the each block is doing to rewrite things as ctx[n] references is apparently not happening in await blocks.

@ghost
Copy link

ghost commented Dec 6, 2019

@Conduitry,

The call to block.renderer.reference(node) is failing on this.context_lookup.get(name) for {#if} block but not {#each} block as you said.

This map is populated by renderer.add_to_context() which seems to not be called for the ThenBlock.

EDIT: More info....

Seems the ThenBlock stores the variable name in .value field whereas EachBlock and IfBlock use .expression with a type of Identifier. I'm still trying to wrap my head around the new stuff so I'll keep digging.

@Conduitry
Copy link
Member

@ghost
Copy link
Author

ghost commented Dec 15, 2019

Yay thanks

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

Successfully merging a pull request may close this issue.

2 participants