Skip to content

What are some common usecases where you would define clientFetcher and serverFetcher both? #11

@saurabhdaware

Description

@saurabhdaware

Saw this in the documentation-

image

My initial expectation from the names clientFetcher and serverFetcher API was that serverFetcher will run on server (so I can fetch some initial data) and then clientFetcher runs post mount where I can fetch some additional data different from what I have on server.

From the current behaviour, it seems like these are more of a getInitialClientData / getInitialServerData kind of functions which let you set the initial data and depending on navigation / load / back button click / etc, either one of them is executed.

Case 1: I define clientFetcher and serverFetcher both

In this case I was wondering, in which scenarios would you want your page to look different if it's page load vs client side navigation? wouldn't the page have same products and data fetching logic on both server and client scenario?

  • What are some scenarios where you're defining different logic in these 2 functions when you define both?
  • This would also mean I see different page depending on whether I navigated to this page with <Link/> (or with <Link target="_blank"> or with <a/> 🤔 )

These concerns could be because its a bit different way to fetch data than what is defined in other frameworks so could be about familiarity as well. The behaviour just looks a little bit error prone in the first sight.

Case 2: I only define serverFetcher

Here, my page works fine on page load but does not load anything on navigation (which I understand from tech perspective that its client navigation) but from consumer-side, it seems a bit unexpected because while developing the app, I see things working as expected on page load but then while specifically testing the client navigation, it suddenly doesn't work.

This might be something that is initially not intuitive but later gets intuitive as people get more familar with framework.

But what would be cooler is if these pages have server navigation by default (might be possible with react server components although I haven't explored it much). Then navigation will also fetch these products


Other than this, everything looks super cool and super well built to me. I love how many edge cases are already covered. The treeshaking also seems to work fine which I initially thought would break seeing this API and love to see that serverFetcher gets clipped out from client-side code 🫡 ❤️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions