Here’s one for the React experts…
My biggest barrier to checking out React with Meteor is how inefficiently some things are handled. I agree in a lot of circumstances these things aren’t that noticeable, but when handling our own animations and working with big lists on mobile, this can be a real pain. Take e.g. the official TODO example:
App = React.createClass({
mixins: [ReactMeteorData],
getMeteorData() {
return { Tasks.find().fetch() };
},
renderTasks() {
return this.data.tasks.map((task) => {
return <Task key={task._id} task={task} />;
},
render() { ... <ul> {this.renderTasks()} </ul> ... }
});
So let’s say we have 2000 tasks already rendered, and a new one is added. What happens?
-
getMeteorData()
is invalidated andTasks.find().fetch()
is rerun. So minimongo has to rebuild the entire list from scratch. -
renderTasks()
is rerun after the state change, iterating from scratch (viamap()
) over the entire query result set and rendering 2001 nodes to the virtual dom. -
vdom diff (which iterates over 2001 children to figure out that 1 was added) and patch 1 element to the DOM.
That was painful just to type. Let’s look at Blaze: 1) cursor addedAt
callback fired with just the new record, 2) Blaze.Each instance’s addedAt
callback is run and a single view is renderered (and added to the DOM). In a super simple test, this is how long it took in each case to add the 2001st row:
- Blaze: ~2 ms
- React: ~160 ms
- React: ~68 ms (after adding
shouldComponentUpdate
)
Is this solveable? Is anyone looking into a way to hack react and hijack the regular state update path? Is that idea an abomination that breaks react core principles and its implementation would be heresy? Is there already some advanced React feature I’m not aware of that helps address this?
I saw a proposal for sideways data loading with a gazillion comments including other proposals (even a ref to Meteor’s Tracker) and no consensus in sight. It wasn’t so obvious (to a React newcomer, at least) how exactly it would work and what problems it solves. Is this the missing magic we need? Will it ever land?
cc: @sashko - your input would be very welcome