rocicorp/replicache-old

Feature Request: Parameterize ClientView Requests

Closed this issue · 2 comments

Problem

Right now the client view request is completely stateless: it carries no per-request data, and therefore, the response can depend only on the state of the data layer, not directly on anything client-side.

There are many examples of cases where it would be useful for the client view response to be dependent upon some client-side state:

  1. The client has just navigated to some view - it would like to indicate to the server that the corresponding data should be prioritized to include.
  2. The server would like to reduce load on its own backend services. If it could store data in the client view that would be sent back to it in the request, it could prioritize which requests to make.
  3. If the complete client view can take a long time to build, then it would be useful to return it in stages. In that case, knowing which bits the client already has is important for the server to know when building a response.

Proposal

What we require is something analogous to an HTTP cookie. A little bit of state that the server can set and get back on the next request to remind itself what it was doing. Or alternately, something a client can set to parameterize the request to the server.

Details

  • Keys in the client-view beginning with "data/" are downstream-only. They act as all entries do today.
  • Keys in the client-view beginning with "cookie/" are cookies. They act exactly as other keys (and are modified the same way), with the addition that they get serialized and sent in each client-view request as part of the POST payload.

Note

Just as with HTTP cookies, this doesn't add anything that developers can't do today. Because each Replicache client does already carry a unique client ID, and each client-view request does uniquely identify its current state ID, anything you can do with this proposal can already be done by storing data in server-side storage keyed by state ID.

This proposal just makes it easier.

Moved this issue into the repc repo: rocicorp/repc#177

I'm going to leave this open for now and refer to it from the bug in repc.