-
Notifications
You must be signed in to change notification settings - Fork 31
feat: lazy loading huge main page components #449
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
base: main
Are you sure you want to change the base?
Conversation
src/components/IntersectionLoadComponent/IntersectionLoadComponent.tsx
Outdated
Show resolved
Hide resolved
| }; | ||
|
|
||
| const getComponentProps = async () => { | ||
| const contributors = await Api.instance.fetchAllContributorsWithCache(); |
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.
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.
I added Next.js server-side endpoint at src/pages/api/contributors.ts and a fetchAllContributorsFromClient method to the Api that calls api/contributors
This seems to have solved the issue
src/pages/api/contributors.ts
Outdated
| return; | ||
| } | ||
|
|
||
| const contributors = await Api.instance.fetchAllContributorsWithCache(); |
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.
@stepanenkoxx take a look plz, as far as I remember, the cache inside Api.instance didn't work with API routes, but now in dev and prod modes everything looks okay.
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.
As I remember, the problem was that Next worked in such a way that the API routes and pages had different instances of Api class
So cache in API routes and cache in pages works but it's different cache, so it will add some more actual github api calls
I will check it now
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.
yes, i checked and there are really different instances
so contributors cache warmup in /health route doesn't make sense now
don't know, maybe we must call Api class methods only in api route "layer" and make api routes for all methods
and call this routes from server and client
src/api/index.ts
Outdated
| async fetchAllContributorsFromClient(): Promise<Contributor[]> { | ||
| const res = await fetch('api/contributors'); | ||
| return (await res.json()).contributors; | ||
| } | ||
|
|
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.
Maybe we should separate classes here for ServerApi and ClientApi?
To avoid confusion and not call server methods from the client
1aa6fc0 to
f7ed75f
Compare







Added HOC to lazy load component when it reaches viewport
Made all examples tabs and contributors list lazy loaded on the main page to optimize perfomance