Skip to content

Nested loader is called twice and has itself as a parent when parent loader resolves instantly #2684

@Truevoly

Description

@Truevoly

Reproduction

https://stackblitz.com/edit/vitejs-vite-avh6zm6f?file=src%2Fcomponents%2FChildPage.vue,src%2Floaders%2FhomeLoader.ts

Steps to reproduce the bug

  1. Open reproduction link
  2. Open console, each loader has a console.log statement at the top to see when each loader is executed.
  3. Verify that on initial load "parent-page" loader is called twice
  4. See that first loader is called twice
  5. Add breakpoint at parentLoader
  6. Uncomment line in ChildPage.vue.
  7. Refresh the preview
  8. See that parentLoader is called in infinite loop

Expected behavior

Each loader is only called once per navigation

Actual behavior

First loader is called twice. If line in child component is uncommented, first loader is called in infinite loop

Additional information

Setup includes a helper component that resolves a loader and provides slot with loaded data.
In my app, I have more than one child page, and so I've added simple caching to avoid refetching parent loader when navigating between them. This simple cache also persists when going back. If you remove caching and force it to reload every time, it will work as intended

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞 bugthis isn't working as expected🔄 data-loadersrelated to Data Loaders

    Type

    No type

    Projects

    Status

    🆕 Triaging

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions