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

docs: add HydrateFallback to the data-loading doc #12601

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brookslybrand
Copy link
Contributor

@brookslybrand brookslybrand commented Dec 20, 2024

We didn't really have any info on HydrateFallback or what clientLoader.hydrate = true does, so hopefully this helps fill in the gap

Copy link

changeset-bot bot commented Dec 20, 2024

⚠️ No Changeset found

Latest commit: e273256

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -9,6 +9,8 @@ Data is provided to the route component from `loader` and `clientLoader`.

Loader data is automatically serialized from loaders and deserialized in components. In addition to primitive values like strings and numbers, loaders can return promises, maps, sets, dates and more.

The type for the `loaderData` prop is [automatically generated][type-safety].

## Client Data Loading

`clientLoader` is used to fetch data on the client. This is useful for pages or full projects that you'd prefer to fetch data from the browser only.
Copy link
Contributor

Choose a reason for hiding this comment

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

I might introduce HydrateFallback here since it can/should be used for this scenario where you have only a clientLoader, and no loader. In that scenario, clientLoader.hydrate defaults to true because we have to run it on hydration if we have no loaderData from the server.

Then below you can mention:

  • When you provide a server loader in addition to a clientLoader, we can render the during SSR using the server loader data
  • If if we do not want to render the route with only server loaderData, then set clientLoader.hydrate=true to run on hydration and provide a HydrateFallback to render until clientLoader completes

Comment on lines +132 to +133
const serverData = await serverLoader();
const res = await fetch(`/api/products/${params.pid}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels redundant? In remix we showed off the common use cases in a dedicated page so maybe we pick what we think is the most common (presumably "skip the hop") and inline it into this doc but then we copy over the Remix doc and link off to it for advanced use cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah agreed. Initially I was combining that doc with the full stack data doc we had, but then realize we already had this doc

I think a dedicated advanced data loading explanation or how-to is a good idea. I’ll try to put something together, even if it’s just a starting point we can improve upon later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants