Live data from Hacker News

Data fetching on the web still sucks

performancejs.com

21–30 of 98 posts

Re: Data fetching on the web still sucks

#21

SWR or react-query?

I started my current project using SWR and then switched to react-query after dealing with some annoyances with SWR. Overall react-query is impressive for data fetching, but I’ve run into issues with mutations and cache invalidation.

I've been disappointed at how SWR and react-query seem to only support the bare minimum for mutations. As far as I can tell, they don't offer any kind of protection from refreshes overwriting any local mutations that haven't been saved to the server yet. They don't do any handling around updating the data on the server, so you need to handle issues yourself like retrying, deciding when to send to the server, and making sure you never have overlapping update requests racing each other. I've had trouble finding any library in the React or general JS ecosystem that handles this stuff.

Re: Data fetching on the web still sucks

#22
Safe client-side SQL sounds like what the author wants.

* Consistency when fetching data: define a UI that matches a particular SQL view.

* Request batching: It's probably not hard to send deltas on a large view with server-side support for sessions.

* Avoiding network waterfalls: basically the definition of a SQL view, with some session management to de-duplicate traffic when updating the view. A lot of clients support batching queries.

* UX when fetching data: this seems entirely like an oversite of some UI packages, but when all the other points line up there are very distinct points in application flow when the UI will know a query and potential update is in progress.

* Colocation: the definition of a view is necessarily local.

* File size: SQL is pretty lightweight on the schema details in results

* Type safety: SQL doesn't support dependent types, but e.g. postgres is pretty type-y

* Versioning: no explicit support in SQL but for changes to the UI a new view can be created. For changes to the data model a compatible change to the view can be committed in the same transaction as the data model change.

* Realtime updates: the glaring hole in the glory of SQL. You'll have to do some user-defined triggers server-side to support this.

* Consistency when updating data: the relational model with constraints enforces this

* Optimistic updates: if the theoretical differential view update described above exists then this is pretty trivial. Compare local and remote deltas when refreshing the view and indicate to the user the expected state that wasn't committed.

* Request queueing: this one seems to be more of a data model problem. If the data model approximates a state machine and queries are on transitions then yes, they need to be serialized. But why not do complex updates all at once with a multi-statement update transaction that commits or fails atomically?

* UX when updating data: presumably a UI tied to a single view is easier to indicate busy-ness for. If an update transaction is in flight, display a spinner. When it fails or commits display an OK or error.

* Durability when updating data: this could almost certainly be improved for most sql clients. However, idempotence is definitely covered by conditional update transactions.

* Type safety: user defined types if necessary but constraints are where a lot of the type-safety happens in SQL.

* Versioning: backward-compatibility by updating mutable views in the same transaction as data model changes. Forward-compatibility by rendering directly from the view that's returned, not expecting any particular view.

Re: Data fetching on the web still sucks

#24
This post feels like a uninformed and undifferentiated rant against "things are too complex". Let's start with the first paragraph: What does the JavaScript fetch API have to do with data management? How can you compare the fetch() API with Swagger (an API documentation format) with Protobuf (a serialisation format)? That doesn't even make sense.

Second paragraph: "The UI should automatically update everywhere the data is used". Again, what does this have to do with any of the above? That is state management, yeah, and you can build proper state management with any HTTP library and any message serialisation format.

Request batching: How would that happen "automatically"? By waiting to fire requests and then batching them?

UX when fetching data: What does that have to do with any of the above? You still have to decide how your UI displays the fact that a piece of data is loading. What do you expect there to be in place? Best thing I could imagine is to have a global operations indicators a la Adobe Lightroom which tells you how many HTTP requests are in flight.

I could go on, but the last paragraphs maybe highlights the lack of understanding the author had: "UI Frameworks (at this point, React has won)". If React had "won" then why would we be having this discussion. React hasn't "won" because it solves one piece of the puzzle: Rendering. For every little other thing you have to incorporate another library or figure out your own solution: Routing, State Management, CRUD / HTTP API, etc. If anything, Ember.js would most closely fit the bill of incorporating most of the things the author seems to care about yet can't articulate clearly.

Re: Data fetching on the web still sucks

#26
post #24

This post feels like a uninformed and undifferentiated rant against "things are too complex". Let's start with the first paragraph: What does the JavaScript fetch API have to do with data management? How can you compare the fetch() API with Swagger (an API documentation format) with Protobuf (a serialisation format)? That doesn't even make sense. Second paragraph: "The UI should automatically update everywhere the da…

What this person said! ^

almost all of the mentioned issues have solutions out their but the author is jumping around the stack with no sense of true purpose. How does graphql impact your SPA updating views, it doesn’t..

Re: Data fetching on the web still sucks

#27

Ember.js seems to check off a lot of those boxes, if you are willing to use a complete solution and not do the 'pick and choose' method of react and friends. While it has lost popularity in the last few years, it has been moving forward technically. It has become leaner and meaner. Really learning the "Ember Way" to do things can reduce some of the friction the author mentions. Ember Data can allow you to talk to mul…

I'm saddened to see that almost a decade after Ember's release, the front-end world still insists rolling their own (terrible) reimplementation of it.

I would've expected that a decade later we would've settled on an Ember-like framework for the front-end and moved beyond constructing URLs and parsing JSON responses manually but apparently not.

Re: Data fetching on the web still sucks

#28
post #24

This post feels like a uninformed and undifferentiated rant against "things are too complex". Let's start with the first paragraph: What does the JavaScript fetch API have to do with data management? How can you compare the fetch() API with Swagger (an API documentation format) with Protobuf (a serialisation format)? That doesn't even make sense. Second paragraph: "The UI should automatically update everywhere the da…

I actually think the problems outlined are pretty valid.

Yeah, there are solutions to them, but I think what the author is saying is that you have to subscribe to something batteries-included, like Meteor, or otherwise implement the solutions yourself from bits and pieces.

Re: Data fetching on the web still sucks

#29

SWR or react-query?

I started my current project using SWR and then switched to react-query after dealing with some annoyances with SWR. Overall react-query is impressive for data fetching, but I’ve run into issues with mutations and cache invalidation.

Hey! SWR author here. Mind sharing the annoyances and how I can make it better for you?

Re: Data fetching on the web still sucks

#30

Ember.js seems to check off a lot of those boxes, if you are willing to use a complete solution and not do the 'pick and choose' method of react and friends. While it has lost popularity in the last few years, it has been moving forward technically. It has become leaner and meaner. Really learning the "Ember Way" to do things can reduce some of the friction the author mentions. Ember Data can allow you to talk to mul…

Seconded, it even handles batching for you.
Post reply on HN