Skip to content

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

@freshgiammi

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

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