sveltejs / sapper

The next small thing in web development, powered by Svelte
https://sapper.svelte.dev
MIT License
6.99k stars 433 forks source link

Conditional rendering component in _layout.svelte causes _error.svelte template stacking up repeatedly #860

Open POPOEVER opened 5 years ago

POPOEVER commented 5 years ago

Describe the bug When using conditional render in top-level route _layout.svelte, _error.svelte template stacks itself up twice.

Code

{#if segment !== undefined}
    <Nav {segment} />
{/if}

Result

QQ20190827-122240@2x

Even in a fresh Sapper clone, when I do nothing but turn <Nav {segment} /> in _layout.svelte into

{#if segment !== undefined}
    <Nav {segment} />
{/if}

Then when I navigate away from 404 page into a top-level route page, this is what happens

QQ20190827-180347@2x

Expected behavior What I'm trying to do is to hide navbar component on the homepage, I tried to remove navbar component from top-level _layout and import the navbar to nested route _layout, but I don't know why segment doesn't work in nested route _layout, it's always logged as undefined, that's why I use conditional render syntax in top-level _layout as the solution so far.

Information about your Sapper Installation:

Severity It makes my page unusable, I'm not sure how severe it is, but to me, it's like 10 out of 10, because I found no routing solution to fix it.

jspinella commented 4 years ago

Have you tried removing <div id='sapper'>%sapper.html%</div> from template.html? This removed the duplicate component from my pages. If you have client.js "imprint" the app onto body (e.g. target: document.querySelector('body')) you shouldn't need the #sapper div container.

ponchoalv commented 4 years ago

Same bug here, I tryed @jspinella suggestion but the stacked render continues.

aewing commented 4 years ago

I'm having this issue as well.