Skip to content

Instantly share code, notes, and snippets.

bvaughn /
Last active February 28, 2024 20:34
Chrome's copy+paste behavior and content editables

Start with this HTML:

<div>click here</div>
<div style="user-select: none;">read-only (no-select)</div>
<div contenteditable style="user-select: none;">editable (no-select)</div>
<div>release here</div>

Click at the top ("click here") and drag down and release at the bottom ("release here"). The following text will be selected:

Screenshot 2024-02-28 at 3 16 26 PM

bvaughn / record-with-chromium
Last active October 20, 2023 08:55
#!/usr/bin/env node
const { spawn } = require("child_process");
const util = require("node:util");
const exec = util.promisify(require("node:child_process").exec);
async function main() {
bvaughn / console-colors.js
Last active July 6, 2022 23:32
Color logging utils for Node and the browser
const COLORS = {
background: {
bgBlack: {
browser: [0, 0, 0],
node: "\x1b[40m",
bgRed: {
browser: [255, 0, 0],
node: "\x1b[41m",
bvaughn /
Last active January 9, 2023 15:46
Experimental React DOM test selector API

RFC Test Selectors

Owner: Brian Vaughn

As of facebook/react/pull/22760, the experimental Test Selector API is now available in the experimental release channel.

To test the API, first install the experimental release:

bvaughn / exercise-app.html
Created November 12, 2021 01:37
Countdown app for exercising
<!DOCTYPE html>
<label>Rest for <input id="restCountInput" value="10" /></label>
<label>Exercise for <input id="activityCountInput" value="30" /></label>
<button id="startStopButton">Start</button>
<p id="countLabel"></p>
<script type="text/javascript">
bvaughn / theme.json
Created October 21, 2021 15:23
React Conf 2021 - Code Sandbox theme
"name": "React Conf 2021",
"type": "dark",
"semanticHighlighting": false,
"colors": {
"contrastBorder": "#122d42",
"focusBorder": "#122d42",
"foreground": "#d6deeb",
"widget.shadow": "#011627",
"selection.background": "#4373c2",
bvaughn / index.html
Created August 27, 2021 22:53
Network caching test harness
<!DOCTYPE html>
<select id="cacheModeSelect">
<script type="text/javascript">
bvaughn / setupFilesAfterEnv.js
Created August 23, 2021 21:37
Jest config to remove extra console location / formatting noise
import { CustomConsole } from '@jest/console';
function formatter(type, message) {
switch(type) {
case 'error':
return "\x1b[31m" + message + "\x1b[0m";
case 'warn':
return "\x1b[33m" + message + "\x1b[0m";
case 'log':
bvaughn /
Created July 8, 2021 18:07
Contributing to React DevTools

Intrested in contributing to React DevTools, but not sure where to start? This gist should hopefully get you going.

Install project dependencies

To get started, check out the React repo:

git clone

Next install dependencies:

bvaughn /
Created June 4, 2021 22:01
Merging client and server trees

Adding Server Component support to DevTools is going to be a big lift, but generally speaking there are a few initial things to work out:

  • Updating the Flight server renderer to stream server component names/types to the client.
  • Adding a new hook to DevTools for the Flight client to call.
  • Merging the server component subtrees into the DevTools client tree.

Yesterday and today I've been thinking about this last item, and I'm feeling pretty stumped at the moment. Merging the trees isn't that difficult, but preserving the tree across client updates gets nasty when it comes to things like conditionally rendered elements.

Setting performance concerns aside, even if I were to undo the merged trees, apply the client updates, and then redo the merge– I'm still not sure we would definitely end up with the correct final state.

For example, consider the following client component that accepts "children" rendered by a server component: