You Really Don’t Need All That JavaScript [video]
His example of using portals to solve &quot;a real problem&quot; is really interesting to me, because it seems to point to a much more fundamental problem with UI development via HTML and browsers.<p>The example involves a common page design: left hand table of contents, right hand (typically most of the width) with current contents (chosen via ToC). Jump to a new section, and the scroll position in the ToC is lost.<p>He describes how to use a portal to fix this.<p>Compare with desktop GUI toolkits. The ToC would be its own element (GtkListView or QtWhateverList or NSThisNThat). The contents would be their own element (GtkTextView or QtCanvas or whatever). Both are drawn independently of the other. You can call for an invalidation of part of the window. You do not need to consider them part of a single window rectangle that will always be redrawn in-toto for a page load.<p>Now, my (weak) understanding of why we&#x27;ve ended up with things like React is that in part they are an attempt to solve this by effectively creating the equivalent of a widget heirarchy inside the browser. When a React implementation of his example gets new content, it doesn&#x27;t invalidate or even necessarily &quot;redraw&quot; the ToC, and it tells the browser what to do by invalidating certain DOM elements (or even just one DOM element).<p>I think he misses this as a key reason for the movement towards frameworks.<p>But ... notice that the browser will probably (I&#x27;m not 100% sure about this, would appreciate comment from someone who knows), re-render the entire rectangle the contains the page.<p>Desktop applications don&#x27;t work this way. If you turn on Quartz debugging on macOS you can actually see the rects on screen that are re-rendered to reflect invalidation by the application (e.g. after new content needs to be displayed).<p>Maybe I have this wrong, and React and similar frameworks have leveraged a subtle capability in the browser to invalidate a DOM element as a way to only re-render part of the on-screen rect.<p>But assuming that I&#x27;ve have this roughly correct, this model in which the &quot;atomic, indivisible rendering unit&quot; for browser apps is the page rect seems fundamentally disadvantaged and mis-designed compared to desktop apps.