Skip to content

Instantly share code, notes, and snippets.


Sebastian Markbåge sebmarkbage

View GitHub Profile
sebmarkbage /
Created Sep 4, 2019
Why is React doing this?

I heard some points of criticism to how React deals with reactivity and it's focus on "purity". It's interesting because there are really two approaches evolving. There's a mutable + change tracking approach and there's an immutability + referential equality testing approach. It's difficult to mix and match them when you build new features on top. So that's why React has been pushing a bit harder on immutability lately to be able to build on top of it. Both have various tradeoffs but others are doing good research in other areas, so we've decided to focus on this direction and see where it leads us.

I did want to address a few points that I didn't see get enough consideration around the tradeoffs. So here's a small brain dump.

"Compiled output results in smaller apps" - E.g. Svelte apps start smaller but the compiler output is 3-4x larger per component than the equivalent VDOM approach. This is mostly due to the code that is usually shared in the VDOM "VM" needs to be inlined into each component. The tr

sebmarkbage / The
Last active Jan 18, 2023
The Rules of React
View The

The Rules of React

All libraries have subtle rules that you have to follow for them to work well. Often these are implied and undocumented rules that you have to learn as you go. This is an attempt to document the rules of React renders. Ideally a type system could enforce it.

What Functions Are "Pure"?

A number of methods in React are assumed to be "pure".

On classes that's the constructor, getDerivedStateFromProps, shouldComponentUpdate and render.

View Infrastructure.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
if (pending.has(url)) {
throw pending.get(url);
sebmarkbage / SubscriptionIsHard.js
Last active Oct 11, 2020
Subscription Is Hard?
View SubscriptionIsHard.js
class SubscriptionDoneRight extends Component {
state = {
getDerivedStateFromProps(props, state) {
return {
sebmarkbage / propertynames.txt
Last active Aug 23, 2017
Attribute/Property Name Smoke Test
View propertynames.txt
sebmarkbage / API.js
Last active Aug 11, 2020
Custom Stack Frames
View API.js
type FrameScope = {
[key:string]: mixed
type StackFrame = {
name?: string,
fileName?: string,
lineNumber?: number,
columnNumber?: number,
scope?: FrameScope
View shortout.js
(function() {
/** Used to detect hot functions by number of calls within a span of milliseconds. */
var HOT_COUNT = 800,
HOT_SPAN = 16;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeNow =;
sebmarkbage /
Last active Mar 9, 2017
ECMAScript Tagged Object

Tagged Objects

The goal is to implement a form of pattern matching that works well in the existing dynamic environment of ECMAScript.

The goal is to find a way to do efficient pattern matching such as using an object tag. JS VMs already have a field for this that is used to tag various kinds of built-in objects.

This tag could be extended to also include a user space range.

The Mechanism

sebmarkbage / asyncToReact.js
Last active Oct 4, 2021
Convert Async Function to React Component
View asyncToReact.js
function asyncToReact(fn) {
class PromiseComponent extends React.Component {
state = { waiting: true, result: null };
componentDidMount() {
fn(...this.props.args).then(result => this.setState({ waiting: false, result }));
componentDidUpdate() {
fn(...this.props.args).then(result => this.setState({ waiting: false, result }));
shouldComponentUpdate(newProps) {
sebmarkbage /
Created Aug 9, 2016
React Isomorphic Package
* React v16.0.0-alpha
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.