Skip to content

Conversation

@simonbs
Copy link
Contributor

@simonbs simonbs commented Aug 14, 2024

This PR is made in response to this comment from @mpabarca, which raises a great point that Shape Docs isn't taking advantage of React's Suspense or other built-in features of Next.js for managing loading states.

While this PR doesn't fully address all the points made in the comment, it addresses part of it. Specifically, this PR removes our /api/user/projects endpoint, which we previously used alongside SWR to refresh the user's list of projects.

Instead, we now fetch the projects directly from our IProjectDataSource in the ProjectList component. When doing so, we utilize Suspense with a fallback that includes the following logic:

  1. Display projects retrieved from our server-side cache, specifically from Redis.
  2. If there are no projects cached server-side, display a loading state.

I have not previously worked with Suspense and Next.js' features for managing loading states, so I would greatly appreciate feedback on the approach presented in this PR to learn how to do it best 🙏

@simonbs simonbs requested a review from mpabarca August 14, 2024 14:01
@simonbs
Copy link
Contributor Author

simonbs commented Aug 14, 2024

It was a challenge to ensure that the logic was properly split between the server-side and client-side, specifically making sure that anything using useContext(...) runs on the client-side, while the component fetching the data from our IProjectDataSource (DataFetchingProjectList, in our case) resides on the server-side. That's why a relatively large number of files are changed in this PR.

@simonbs simonbs marked this pull request as ready for review August 20, 2024 08:28
@simonbs simonbs requested a review from ulrikandersen as a code owner August 20, 2024 08:28
@mpabarca mpabarca self-requested a review August 20, 2024 08:49
@simonbs simonbs merged commit e61cca2 into develop Aug 20, 2024
@simonbs simonbs deleted the enhancement/load-projects-with-suspense branch August 20, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants