relay-tools / relay-hooks

Use Relay as React hooks
https://relay-tools.github.io/relay-hooks/docs/relay-hooks.html
MIT License
540 stars 56 forks source link

[proposal] improve rendering for query without incremental data #238

Closed morrys closed 8 months ago

morrys commented 1 year ago

the request comes from this comment:

Hi @morrys, thanks for explaining the behavior in detail. One follow-up question, is there a way to opt out of partial/incremental rendering? I would prefer having 2 re-renders.

It would be interesting to investigate the possibility of identifying queries that call next only once during fetch.

This would allow us to implement automation, such as for polling, and avoid introducing a new parameter to be passed to useQuery and useLazyLoadQuery.

morrys commented 1 year ago

@sibelius do you know what are the use cases when next is called only once? 💯

morrys commented 1 year ago

@Lalitha-Iyer I'm considering modifying the onNext function in QueryFetcher like this:

const onNext = (
    _o: OperationDescriptor,
    snapshot: Snapshot,
    response: GraphQLResponse,
): void => {
    if (!this.snapshot) {
        this.snapshot = snapshot;
        this.subscribe(snapshot);
        this.resolveResult();
        const responses = Array.isArray(response) ? response : [response];
        const isFinal = responses.some((x) => x != null && x.extensions?.is_final === true);
        if (fetchHasReturned && !isFinal) {
            this.forceUpdate();
        }
    }
};

So anyone in the relay network can add that information to the response and change the behavior of useQuery.

Lalitha-Iyer commented 1 year ago

I would prefer an option over isFinal, just because it's would be easier to build an abstraction on top. Eventually, we could move to the model of automatically figuring out when to skip the extra re-render, and then this option would be used as an escape hatch to force an extra re-render in case unknown bugs come up.

morrys commented 8 months ago

released with version 8.0.0