Skip to content

preload: undefined context in loader if navigation happens before beforeLoad is done #1886

Closed

Description

@freshgiammi

Describe the bug

There's still an issue here when with context when it gets merged with beforeLoad.

export const Route = createFileRoute('/about')({
  beforeLoad: async () => {   
    await new Promise((resolve) => setTimeout(resolve, 5000));
    return { someData: 'hello' };
  },
   loader: async ({context}) => {
    await new Promise((resolve) => setTimeout(resolve, 2000));
    console.log(context.someData)
  },
})

Supposing /about is the lazy route that takes a long time to resolve, if beforeLoad isn't finished before the navigation event happens, the loader gets invoked with an undefined context, breaking the route.

This possibly happens because execution flow is skipped when a route already in beforeLoad fetching state is re-loaded (because the loader gets invoked regardless of the beforeLoad state, for which we have no pending information on reload)

Your Example Website or App

https://stackblitz.com/edit/github-nkiyw7

Steps to Reproduce the Bug or Issue

  1. Hover About link
  2. Immediately click to navigate before the 5000ms beforeLoad is done executing
  3. Undefined context in loader 🤯

Expected behavior

As a user, I expect context to not be undefined

Screenshots or Videos

No response

Platform

  • OS: MacOS
  • Browser: Chrome
  • Version: 1.43.6

Additional context

No response

Activity

  1. schiller-manuel commented on Jul 6, 2024

    @schiller-manuel
    Collaborator
  2. freshgiammi commented on Jul 6, 2024

    @freshgiammi
    ContributorAuthor
  3. schiller-manuel commented on Jul 6, 2024

    @schiller-manuel
    Collaborator

    yes we'll close #1891, but I will take over the test from there, so thanks for implementing that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions