Skip to content

Svelte component is rendering despite guard clause #17106

@KieranP

Description

@KieranP

Describe the bug

We deployed PR #16930 to production yesterday, and it does appear to have reduced instances of errors, but sadly we saw another case come through Rollbar today, so the PR doesn't fully resolve the issue. Issue we're seeing boils down to the following:

parent.svelte

<script lang="ts">
  const currentChildPage = $derived(
    $pageStore && pageStore.getActiveState().activeChildPage
  )
</script>

{#if currentChildPage}
  <ChildPage childPage={currentChildPage} />
{/if}

child_page.svelte

<script lang="ts">
  const { childPage } = $props()
  const singlePageItem = $derived(childPage.page_items.length === 1)
</script>

{#if singlePageItem}
  ...
{:else}
  ...
{/if}

Error in child.svelte line 3:

TypeError Cannot read properties of undefined (reading 'page_items')

So somehow, child_page.svelte is rendering with childPage == undefined, even though we wrap that childPage rendering in a {#if currentChildPage} guard.

Reproduction

Unfortunately, I am not able to replicate the issue in the playground. It is a race condition that seems to happen 5-6 times a week in a large production application.

Logs

System Info

System:
    OS: macOS 26.0.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 1.58 GB / 18.00 GB
    Shell: 5.9 - /opt/homebrew/bin/zsh
  Binaries:
    Node: 24.8.0 - /Users/kieran/.asdf/installs/nodejs/24.8.0/bin/node
    npm: 11.6.0 - /Users/kieran/.asdf/plugins/nodejs/shims/npm
    pnpm: 10.20.0 - /Users/kieran/.asdf/installs/nodejs/24.8.0/bin/pnpm
    bun: 1.3.1 - /opt/homebrew/bin/bun
    Deno: 2.5.6 - /opt/homebrew/bin/deno

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting submitterneeds a reproduction, or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions