Skip to content

Caching for preloaded layouts routes not working #4112

@MTG2000

Description

@MTG2000

Which project does this relate to?

Router

Describe the bug

When preloading a route (by hovering on a link for example), the preloaded data is kept in the cache for some time (default is 30 seconds) & no new requests will be made even when hovering on the same link again.

I noticed this behaviour doesn't work as expected when there's a layout in the preloaded route.

Check the reproduction example or the video below:

I've set the defaultStaleTime to 5 seconds, after those 5 seconds, every time I hover on the About link, the layout route loaded is invoked without being cached.

Recording.2025-05-08.150312.mp4

Your Example Website or App

https://stackblitz.com/edit/github-51knrjza-peyz37du?file=src%2Fmain.tsx

Steps to Reproduce the Bug or Issue

  1. Go to home page
  2. Wait for at least 5 seconds
  3. Hover over the 'About' link repeatedly and observe the console logs
  4. You will see the Layout loader message appearing every time you hover on the link without any caching. (Where as the About loader is cached properly)

Expected behavior

The expected behaviour is for the layout routes loaders to be cached like normal routes pages.
The docs don't specify any special treatment for layouts AFAIK.

Screenshots or Videos

Recording.2025-05-08.150312.mp4

Platform

  • OS: Linux
  • Browser: Chrome
  • Version: 135

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions