Skip to content
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

Colocate data fetching; use proper server components #4

Merged
merged 3 commits into from
Apr 4, 2024

Conversation

unstubbable
Copy link
Owner

@unstubbable unstubbable commented Mar 18, 2024

Performing all image search requests upfront, before rendering any image components, wasn't really in line with how server components should work. This approach was initially chosen to obtain a single function AI state that contains data from all searches.

With the introduction of the onDataFetched prop, we can achieve the same outcome while moving data fetching directly into the server components, where it belongs.

This change also makes it easier to add loading skeletons later on.

The approach does have the downside that we need to follow this kind of awkward rendering approach:

  • map over searches to create pairs of elements and their data promises
  • yield the elements as part of the "final UI" (but suspended)
  • await all the data from the child components, and put it into the AI state
  • return the final UI

@unstubbable
Copy link
Owner Author

unstubbable commented Mar 18, 2024

This only works in development mode for some reason. In production mode (also locally), the intermediate UI is removed in the client, when the final RSC rows have been processed.

Performing all image search requests upfront, before rendering any image
components, wasn't really in line with how server components should
work. This approach was initially chosen to obtain a single `function`
AI state that contains data from all searches.

With the introduction of the `onDataFetched` prop, we can achieve the
same outcome while moving data fetching directly into the server
components, where it belongs.

This change also makes it easier to add loading skeletons later on.
@unstubbable unstubbable marked this pull request as ready for review April 4, 2024 09:17
@unstubbable unstubbable merged commit 54af578 into main Apr 4, 2024
5 checks passed
@unstubbable unstubbable deleted the colocate-data-fetching branch April 4, 2024 09:19
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.

1 participant