TanStack / router

🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering.

Home Page:https://tanstack.com/router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined context in loader after redirect

Nr9 opened this issue · comments

Describe the bug

Another problem relating to undefined context.

I'm creating a new issue since I'm NOT using defaultPreload: 'intent'

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-u41fay?file=src%2Froutes%2Ftests.%24testId.reports.create.tsx

Steps to Reproduce the Bug or Issue

  1. Navigate to Navigate to this links fails! (route: /tests/$testId/reports, url: http://localhost:3001/tests/42/reports/create)
  2. Reloading the page at the same url works.

Expected behavior

The context provided to the loader function should not be undefined.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome

Additional context

I do not have this problem with version 1.27.0.

@SeanCassiere The same thing happens to me, when I navigate between routes it goes fine, but when the component enters due to a redirect, if I try to get the context in that component, it is undefined and the app dies

example error:

export const Route = createFileRoute('/auth/verify-email')({
    beforeLoad: async ({ context }) => {
        if (!context.auth.id) {
            throw redirect({
                to: '/auth/verify-phone',
                search: prev => ({ id: prev.id }),
                viewTransition: true
            });
        }
        if (!context.auth.needEmailVerification) {
            if (context.auth.needPersonalInformation) {
                throw redirect({
                    to: '/onboarding/require-legal-information',
                    search: prev => ({ id: prev.id }),
                    viewTransition: true
                });
            }

            if (!context.auth.paymentMethods || !context.auth.paymentMethods.length) {
                throw redirect({
                    to: '/payment-method/add-payment-method',
                    search: prev => ({ id: prev.id }),
                    viewTransition: true
                });
            } else {
                throw redirect({
                    to: '/payment-method/select-payment-method',
                    search: prev => ({ id: prev.id }),
                    viewTransition: true
                });
            }
        }
    }
});

hook into paymentMethodComponent

export const useAddPaymentMethodForm = () => {
    const { urlID, auth } = useRouteContext({ from: '/payment-method/add-payment-method' });

when it enters the before load of the verify email route, the contet works, but when I do the redirect it has to add card, in the addpaymentmethod hook it is undefined

I'm experiencing the same issue in the latest version

We have a PR open that should fix this #1713. We are waiting on some feedback from Tanner before merging it in.

@SeanCassiere I still have the same issue. Nothing changed.

And the main thing that I don't change context anywhere. I just set it and try to use helper functions from it. As a workaround I've made a patch using yarn to remove all functionality related to updating context. Something still overriding context with undefined

@SeanCassiere I still have the same issue. Nothing changed.

And the main thing that I don't change context anywhere. I just set it and try to use helper functions from it. As a workaround I've made a patch using yarn to remove all functionality related to updating context. Something still overriding context with undefined

Please create a new issue with a reproduction, I'd be happy to go through it next week!