Skip to content

Conversation

@TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Oct 23, 2025

with route intent preloading, we show way fewer loaders for lazy-loading assets. However, the loader still shows up when you hard reload a page, or navigate there for the first time. this still leads to cascading loaders, with the first loader (the vertically centered one) being from lazy-loading the static asset:

Screen.Recording.2025-11-11.at.11.05.36.mov

since lazy-loading static assets is usually fast, by deferring the loader by 300ms, we get a better experience for those cases, while still showing a loader should it really take some time:

Screen.Recording.2025-11-11.at.11.07.38.mov

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Oct 23, 2025
@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##           master   #102031       +/-   ##
============================================
+ Coverage   66.22%    80.95%   +14.72%     
============================================
  Files        9139      8818      -321     
  Lines      392478    388452     -4026     
  Branches    24974     24750      -224     
============================================
+ Hits       259926    314458    +54532     
+ Misses     132126     73630    -58496     
+ Partials      426       364       -62     

TkDodo added a commit that referenced this pull request Nov 10, 2025
This PR adds preloading to internal links. To do this, we:

- expose a new `preload` function from `makeLazyLoadComponent`
- attach this method to the route’s `handle`
- invoke the `preload` method on hover / focus of our `<Link>` component
if the Link would go to a route

Note:

- we attach the hover / focus event handlers to _all_ Links, but they
will trigger the promise only once because it’s cached.
- if a route was made without `makeLazyLoadComponent`, it won’t have a
preload function so nothing happens.
- only static assets are preloaded - not data calls

This should ensure that navigations between routes, when going there the
first time, are faster and we don’t have to show loading spinners that
often. Combined with [deferring the fallback for lazy loaded
files](#102031), we should get a
smooth ux for first navigations.

before (notice the big spinner in the middle of the page on each
navigation):
after (notice the big spinner in the middle of the page is gone):
so that custom passed-in loaders can bypass this
@TkDodo TkDodo marked this pull request as ready for review November 11, 2025 10:09
@TkDodo TkDodo requested a review from a team November 11, 2025 10:09
@TkDodo TkDodo merged commit 2c66b4f into master Nov 11, 2025
49 checks passed
@TkDodo TkDodo deleted the tkdodo/feat/defer-lazy-load branch November 11, 2025 14:51
Jesse-Box pushed a commit that referenced this pull request Nov 12, 2025
This PR adds preloading to internal links. To do this, we:

- expose a new `preload` function from `makeLazyLoadComponent`
- attach this method to the route’s `handle`
- invoke the `preload` method on hover / focus of our `<Link>` component
if the Link would go to a route

Note:

- we attach the hover / focus event handlers to _all_ Links, but they
will trigger the promise only once because it’s cached.
- if a route was made without `makeLazyLoadComponent`, it won’t have a
preload function so nothing happens.
- only static assets are preloaded - not data calls

This should ensure that navigations between routes, when going there the
first time, are faster and we don’t have to show loading spinners that
often. Combined with [deferring the fallback for lazy loaded
files](#102031), we should get a
smooth ux for first navigations.

before (notice the big spinner in the middle of the page on each
navigation):
after (notice the big spinner in the middle of the page is gone):
Jesse-Box pushed a commit that referenced this pull request Nov 12, 2025
with [route intent
preloading](#102574), we show
way fewer loaders for lazy-loading assets. However, the loader still
shows up when you hard reload a page, or navigate there for the first
time. this still leads to cascading loaders, with the first loader (the
vertically centered one) being from lazy-loading the static asset:


https://github.com/user-attachments/assets/5a85bf86-74ee-4d1d-b2a9-10121bc7160f

since lazy-loading static assets is usually fast, by deferring the
loader by 300ms, we get a better experience for those cases, while still
showing a loader should it really take some time:


https://github.com/user-attachments/assets/35945187-d594-43b1-8f79-1b8bef4354c7
andrewshie-sentry pushed a commit that referenced this pull request Nov 13, 2025
This PR adds preloading to internal links. To do this, we:

- expose a new `preload` function from `makeLazyLoadComponent`
- attach this method to the route’s `handle`
- invoke the `preload` method on hover / focus of our `<Link>` component
if the Link would go to a route

Note:

- we attach the hover / focus event handlers to _all_ Links, but they
will trigger the promise only once because it’s cached.
- if a route was made without `makeLazyLoadComponent`, it won’t have a
preload function so nothing happens.
- only static assets are preloaded - not data calls

This should ensure that navigations between routes, when going there the
first time, are faster and we don’t have to show loading spinners that
often. Combined with [deferring the fallback for lazy loaded
files](#102031), we should get a
smooth ux for first navigations.

before (notice the big spinner in the middle of the page on each
navigation):
after (notice the big spinner in the middle of the page is gone):
andrewshie-sentry pushed a commit that referenced this pull request Nov 13, 2025
with [route intent
preloading](#102574), we show
way fewer loaders for lazy-loading assets. However, the loader still
shows up when you hard reload a page, or navigate there for the first
time. this still leads to cascading loaders, with the first loader (the
vertically centered one) being from lazy-loading the static asset:


https://github.com/user-attachments/assets/5a85bf86-74ee-4d1d-b2a9-10121bc7160f

since lazy-loading static assets is usually fast, by deferring the
loader by 300ms, we get a better experience for those cases, while still
showing a loader should it really take some time:


https://github.com/user-attachments/assets/35945187-d594-43b1-8f79-1b8bef4354c7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants