-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
refactor(core): prefetch/preload refactor #7282
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site settings. |
e15aab6
to
6bc09e2
Compare
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-7282--docusaurus-2.netlify.app/ |
Size Change: -1 B (0%) Total Size: 805 kB ℹ️ View Unchanged
|
Hmmm, zero size reduction. Slightly disappointed. The pnpm failure is unrelated. It's because pnpm 7.0 was released yesterday with pnpm/pnpm#4427. I will follow-up to fix it. |
prefetch: (url: string) => false | Promise<void[]>; | ||
preload: (url: string) => false | Promise<void[]>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit but what's the advantage of having void[]
here?
Maybe it would be better to use await Promise.all([])
and just have Promise<void>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh... you are right. Not a huge problem though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, wait, we can't use await
. We never use async-await in client code because that bloats the bundle (in fact I also want to reduce ??
and ?.
usages). So in order to make it return void
, we have to chain another .then(() => {})
which is not really ideal.
In addition, when it can't prefetch, false
is returned synchronously, instead of being wrapped in a promise.
Pre-flight checklist
Motivation
With this change:
Set
instead of an object as the memoization layer, which should be more performant & has better semantics.prefetch
memoization has been deduplicated.prefetchHelper
now does not memoize on itself; onlywindow.docusaurus.prefetch
does. This is fine, because we don't callprefetchHelper
directly anywhere else.window.docusaurus.preload
andwindow.docusaurus.prefetch
now returnPromise<void[]>
instead oftrue
, which can allow external callers to wait for them instead of having floating promises.Test Plan
Prefetching work the same. You can confirm by scrolling down a page and see the network cascade expanding whenever a new link is in viewport.