logoalt Hacker News

syspecyesterday at 7:46 PM9 repliesview on HN

Whole blog post is basically: Make a mutation in the clientside, assume it worked, and save in the background.


Replies

mohsen1yesterday at 8:22 PM

Works for Linear because the tab stays open, and worse case if tab is closed you can recover later when the tab is opened again and deal with conflict resolution. Won't work if:

1. user clicks a button and closes the tab thinking transaction is done and it's important that transaction is done

2. conflict resolution is difficult or impossible in future client wake up

show 4 replies
NewsaHackOyesterday at 7:54 PM

I agree. To each their own, but the UI updating automatically doesn't really add much value to me. I would prefer that the view I am seeing is a snapshot in time of what the ground truth server was, not some mixed state that forces me to consider the possibility that seeing my request go through on the screen doesn't actually mean it went through and has been sent to the server.

show 1 reply
aboodmantoday at 12:25 AM

Well that "make a mutation client-side" phrase is doing a lot of work.

Make a mutation to what?

The classic server rendered web-app doesn't have any data to make a mutation to. You could try to patch the UI but that would be a huge pita and not really a scalable (in effort) solution.

If you have an SPA, you still don't really have data on the client-side. You have a bunch of cached query responses. You can update those, but (a) it will be a pita to do correctly, (b) you'll have to do it to every possibly affected query, and (c) you have to remember to undo it at the right time (way more subtle than it appears - think it through!).

A sync engine creates the client-side normalized datastore that allows you to "do a mutation client side". In fact, you're kind of right that once you have a sync engine, just doing a mutation is really easy. The real challenge is all the infra required to enable you to do so.

Aeolunyesterday at 11:11 PM

I think whole generations are constantly discovering that the client is really, really fast.

willsmith72today at 12:23 AM

so.. optimistic ui? like upvotes on hacker news since forever?

prerokyesterday at 7:56 PM

Indeed. I have to say, I hate this. Suppose you are in a meeting, you update something and you see the result, but the rest of the team does not. Ok, a couple of hundred ms does not play into this but if the update does not make it through? And yes, it happens.

show 1 reply
girvoyesterday at 10:30 PM

AKA what Relay does out of the box haha

Though its depressing how few actually use it to its full extent. My team is one of the few where I work; heavy declarative mutation directives with optimisticResponse (and optimisticUpdaters because some of our APIs are not very Relay-compatible, annoyingly)

show 1 reply
pier25yesterday at 7:57 PM

For native apps this is less of an issue since they have access to persistent storage but with browsers there's no guaranteed persistence.

show 1 reply
sneakyesterday at 8:44 PM

I believe this is called “eventual consistency”.

show 1 reply