Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeLoad adds ~400ms delay on page reload #2183

Open
cschmatzler opened this issue Aug 23, 2024 · 5 comments
Open

beforeLoad adds ~400ms delay on page reload #2183

cschmatzler opened this issue Aug 23, 2024 · 5 comments

Comments

@cschmatzler
Copy link

Describe the bug

When adding beforeLoad to a route (even an empty one), the router gets mounted and then displays a white page for approx. 400ms before the actual page is rendered.

Your Example Website or App

https://stackblitz.com/github/tanstack/router/tree/main/examples/react/quickstart-file-based

Steps to Reproduce the Bug or Issue

  1. Fork the file-based QuickStart example on StackBlitz.
  2. Add an beforeLoad: () => {} to any page - I chose the about page.
  3. Go to the page you changed and reload the page in the browser.

Expected behavior

Simply adding the beforeLoad option should not materially change load times.

Screenshots or Videos

router.mp4

Platform

  • OS: macOS Sonoma
  • Browser: Arc
  • Version: 1.56.0

Additional context

No response

@cschmatzler cschmatzler changed the title beforeLoad adds ~400ms delay on page rload beforeLoad adds ~400ms delay on page reload Aug 23, 2024
@mreinertssgr
Copy link

mreinertssgr commented Aug 26, 2024

I've been experiencing this too, however my code might be a little different. Rendering the actual app is delayed by almost 1 second.

const InnerApp = () => {
    const auth = useAuthStore();

    if (auth.loading) {
        return <div>Loading...</div>;
    }

    return (
        <ThemeProvider theme={lightTheme}>
            <CssBaseline />
            <RouterProvider router={router} context={{ auth }} />
            <Toaster />
        </ThemeProvider>
    );
};

export default () => {
    return (
        <StrictMode>
            <QueryClientProvider client={queryClient}>
                <InnerApp />
            </QueryClientProvider>
        </StrictMode>
    );
};

I also checked the performance tab in devtools and it looks like nothing is happening (the selected range is when nothing is rendered)
image

@DaniumX
Copy link

DaniumX commented Sep 1, 2024

As a temporary fix, add pendingMinMs: 0.

@macr
Copy link

macr commented Sep 9, 2024

I just noticed it happening on all the lazy routes.
React profiler shows:
Image
looking at the offending function:

export const Match = React.memo(function MatchImpl({

It does wait for pendingMinMs ms before loading the match.
Is there a catch to just setting pendingMinMs: 0?

@Scooter1337
Copy link

Scooter1337 commented Sep 12, 2024

I just saw this issue and added the temporary fix and my app feels way faster now... This needs a fix.

@mirague
Copy link

mirague commented Sep 24, 2024

Also noticed that adding this makes the app a lot more snappy, especially since we perform a lot of middleware/guard checks in beforeLoad() which takes almost no time. The default pendingMinMs is 500 which is pretty long.

Can be disabled for the entire router by setting defaultPendingMinMs: 0,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants