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

Outro transition not playing if inside #if #each #2689

Closed
bwbroersma opened this issue May 5, 2019 · 3 comments
Closed

Outro transition not playing if inside #if #each #2689

bwbroersma opened this issue May 5, 2019 · 3 comments

Comments

@bwbroersma
Copy link
Contributor

I would expect all items to have the same intro en outro effect, see the bug in action in this REPL demo in version 3.2.0.

The code:

<script>
	import { fade } from 'svelte/transition';
	let checked = true;
</script>

<label>
	<input type=checkbox bind:checked> Trigger
</label>

{#if checked}
	{#each [1] as x }
		<p in:fade out:fade>if each in out</p>
		<p transition:fade>if each transition</p>
	{/each}
	<p in:fade out:fade>if in out</p>
	<p transition:fade>if transition</p>
{/if}
@bwbroersma
Copy link
Contributor Author

bwbroersma commented May 5, 2019

I think the problem in the generated code is:

        // (10:0) {#if checked}
        function create_if_block(ctx) {
        ...
                function outro_block(i, detaching, local) {
                        if (each_blocks[i]) {
                                if (detaching) {
                                        on_outro(() => {
                                                each_blocks[i].d(detaching);
                                                each_blocks[i] = null;
                                        });
                                }

                                each_blocks[i].o(local);
                        }
                }

               return {
                ...
                        o: function outro(local) {
                                each_blocks = each_blocks.filter(Boolean);
                                for (let i = 0; i < 1; i += 1) outro_block(i, 0);

I think the last line should be:

                                for (let i = 0; i < 1; i += 1) outro_block(i, 0, local);

Update: no it shouldn't it should be:

                                for (let i = 0; i < 1; i += 1) outro_block(i, 0, 0);

but that won't fix the problem, that's in another file:

let outro_block = deindent`
${outro_name} = @create_out_transition(${this.var}, ${fn}, ${snippet});
`;
if (outro_block) {
outro_block = deindent`
if (#local) {
${outro_block}
}
`;
}

always adding the if(local) because the check if (outro_block) is wrong, it's clear when looking at the intro code:
if (intro.is_local) {
intro_block = deindent`
if (#local) {
${intro_block}
}
`;
}

@bwbroersma
Copy link
Contributor Author

I think it's generated here:

for (let #i = 0; #i < ${view_length}; #i += 1) ${outro_block}(#i, 0);`

bwbroersma added a commit to bwbroersma/svelte that referenced this issue May 5, 2019
@bwbroersma
Copy link
Contributor Author

bwbroersma commented May 5, 2019

However changing this, 4 runtime tests will fail (or 8 with hydrate):

     ReferenceError: local is not defined

The tests are:

So probably this is not a good fix , but the sample will work.
Update: this is the correct fix:
bwbroersma@5784344

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