Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Lazy load all routes in the frontend #3033

Merged
merged 5 commits into from
Aug 1, 2024
Merged

Lazy load all routes in the frontend #3033

merged 5 commits into from
Aug 1, 2024

Conversation

sandhose
Copy link
Member

@sandhose sandhose commented Jul 31, 2024

This lazy-loads all routes, to trim down the main bundle as much as possible, and optimise for the first contentful paint.
This can be reviewed commit by commit.

  • vite: enable preloading and make sure we load the right dev/prod deps: At some point, because the asset loading was faulty, I disabled pre-loading from Vite. This enables it again, so that all the dependencies of a route get loaded in parallel
  • frontend: lazy-load the password complexity calculation logic: This is an interesting one, it lazy-loads the part which calculates the code complexity, so that we can start rendering without loading all the dictionaries
  • frontend: lazy-load all routes: There is no real logic change in there, just that all routes become .lazy, with the loader in a file and the component in another
  • frontend: don't wait before rendering: Tanstack Router has this default behaviour of waiting 500ms before rendering the route, so that you have a chance to stare at the loading screen. Our loading screen doesn't seem to render, so it was just adding delay on a blank screen
  • frontend: move getNinetyDaysAgo to a shared utility: Just some code deduplication

One thing I noticed is that for some reason, the loaders aren't kicking in until the page components are loaded. They should load in parallel, because this adds a bit to our loading waterfall. I asked on the Tanstack Router discord to see what they think about it.

Non-scientific measurements

This is on the Slow 4G preset

Password recovery page

Before

image

After

image

Account home

Before

image

After

image

@sandhose sandhose requested a review from reivilibre July 31, 2024 12:35
sandhose added 4 commits July 31, 2024 14:36
The default behaviour of Tanstack Router is to wait at least 500ms
before showing the rendered route, so that the loading spinner doesn't
flicker. We don't want that, as we don't seem to have a working loading
spinner anyway, and this just unnecessarily adds FCP latency.
@sandhose sandhose force-pushed the quenting/lazy-load-all branch from 1666f74 to 92aadf8 Compare July 31, 2024 12:36
Copy link

cloudflare-workers-and-pages bot commented Jul 31, 2024

Deploying matrix-authentication-service-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 92aadf8
Status: ✅  Deploy successful!
Preview URL: https://28bf2e2a.matrix-authentication-service-docs.pages.dev
Branch Preview URL: https://quenting-lazy-load-all.matrix-authentication-service-docs.pages.dev

View logs

@sandhose sandhose added the A-Frontend Changes on the React frontend label Jul 31, 2024
Comment on lines +50 to +54
loadPromise
.then(({ estimatePasswordComplexity }) =>
estimatePasswordComplexity(deferredPassword, t),
)
.then((response) => setResult(response));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this potentially 'queue up' a bunch of .then tasks and then run them all at once when the import loads?

e.g. it might trigger multiple times if the user started typing a password before it finishes loading? Further, if the tasks run out of order, it might set the wrong score on the form?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will, but I wouldn't worry too much about it? 🤷

@sandhose sandhose merged commit cb8bfa4 into main Aug 1, 2024
16 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Frontend Changes on the React frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants