They do use React for their TV, but they've actually decided to not use React DOM, and instead create their own WebGL-based, canvas-based renderer, effectively, called React Gibbon. They didn't open-source it, unfortunately, but the whole idea is that they rely on sort of the hardware accelerated graphics on these smart TVs to be able to get better performance, and they don't want to rely on the DOM implementation. And this is an approach that some people like to take in the community, so we mentioned Lightning.js. This is kind of the selling point of Lightning.js for people is that it uses Canvas and is WebGL-based. Similarly, another open-source project is React Ape, which also is a WebGL canvas-based implementation for React-based applications that are targeting TV or other sort of low-end devices.
The challenge with both of these is that in Lightning.js's case, it has very little support from the community. It's got a very small community, especially compared to the React world. 50-odd stars on their most popular repository, that's the equivalent of a weekend project in the React ecosystem that is not being actively maintained or code-gest effectively. So the Lightning.js ecosystem is very small, and that is usually a big concern when you're looking at investable tech that you can rely on for the long term. React Ape, on the other hand, hasn't been maintained for about two years, so those approaches are less popular. And so most people will just opt to still use the DOM and native views when it comes to those native platforms.
And in practice, what that means is when you are using the DOM, you'll need to heavily memoize because you need to minimize the re-renders. You need to create simpler variants of pre-existing community components. So it's not going to be simply just taking some of the components that work on web and just using them on TVs. You're going to need to really make sure that everything that you use is hyper-optimized and not using more resources than you can afford to use. A lot of times, components that are open source and released out by the community are optimized for cursor and touch interactions, so web and mobile, but you don't need those for TV. And performance is the number one priority. And hence, oftentimes it's better to just build it yourself with much less CPU usage or much less performance losses from using pre-built solutions. The other thing that becomes important is to avoid heavy computations on paint, especially when it comes to layouting. And lastly, a lot of virtualization and recycling happens on TVs and TV apps to minimize the number of components that are rendering on a screen. And I'll give you an example of one.
So in the React Native space, on mobile, people often complain about FlatList. FlatList is the default list implementation within React Native, and it is notorious for being slow. People have been complaining about it for years, and Shopify actually released their own version called FlashList of a list component to be able to basically make sure that lists are smooth and performant on React Native applications. And so, naturally, that FlatList component also exists on TV, and some people try to use it for TV, and it is not a good idea. Now, FlatList is virtualized, but what it doesn't have is it doesn't have a recycling mechanism within it. So one of the important things is that we should be able to recycle as many elements as we can. And so when you have a carousel, you don't want to mount and unmount components as the user scrolls through the carousel, because that is a very computationally expensive operation to do. So what you do is you use the same components, and as the user is going through the list, you take components from the beginning of the list, and you move them effectively to the end of the list and update the data that's being displayed. So you consistently have a certain number of elements that are rendered, and you only change what's being displayed for each of them and adjust their position effectively.
Comments