Skip to content

Instantly share code, notes, and snippets.

View jacob-ebey's full-sized avatar

Jacob Ebey jacob-ebey

View GitHub Profile
@jacob-ebey
jacob-ebey / react-use.ts
Last active December 31, 2022 00:46
A very naive implementation of React's use() hook
// A very naive implementation of React's use() hook you can copy and paste into your app today
// to use with solutions such as remix's experimental `defer()` feature.
function use<T>(useable: Promise<T> | T) {
if (typeof useable != "object" || !useable || !("then" in useable)) {
return useable;
}
let promise = useable as Promise<T> & { _data?: T; _error?: unknown };
if ("_data" in promise) {
@jacob-ebey
jacob-ebey / deferred-overview.md
Last active February 28, 2025 05:42
Deferred Overview

Remix Deferred

Remix Deferred is currently implemented on top of React's Suspense model but is not limited to React. This will be a quick dive into how "promise over the wire" is accomplished.

SSR + Hydration

It isn't rocket science, but a quick recap of how frameworks such as react do SSR:

  1. Load data
  2. Render the app
@jacob-ebey
jacob-ebey / flat-routes-universal.ts
Last active December 21, 2022 22:14
Universal Flat Routes
/**
* Create route configs from a list of routes using the flat routes conventions.
* @param appDirectory The absolute root directory the routes were looked up from.
* @param routePaths The absolute route paths.
* @param prefix The prefix to strip off of the routes.
*/
export function flatRoutesUniversal(
appDirectory: string,
routePaths: string[],
prefix: string = "routes"
@jacob-ebey
jacob-ebey / client-navigation.js
Created January 11, 2023 00:53
Navigation and View Transition API example
import { html } from "html-tagged";
export default function ClientNavigation() {
return html`
<script type="module">
if (typeof navigation !== "undefined") {
let lastAbortController;
navigation.addEventListener("navigate", (event) => {
if (!event.canIntercept) return;
@jacob-ebey
jacob-ebey / RSC-exploration.md
Created February 28, 2023 18:44
RSC Exploration

React Server Components Exploration

High level:

  • Separation of SSR vs RSC rendering environments is both unnecessary and a pain point for existing application migration to the new paradigms.
  • "Client Component can't import Server Component" seems to be an artificial limitation of the mental model of separate SSR vs RSC env and the lack of built in support for inlining RSC streams into the HTML document
  • Removal of "client only hooks" is also an artificial limitation brought on by trying to make SSR and RSC independent concepts. Zero reason to remove hooks that work in SSR today to support RSC.
  • Inlining of RSC JSON representation should not be needed and the intermediate tree should be able to be revived from the SSR'd DOM, not an inlined RSC format.
@jacob-ebey
jacob-ebey / bye-bye-blue.js
Created July 28, 2023 17:31
ByeByeBlue Boost
setInterval(() => {
const tweets = document.querySelectorAll(
`[data-testid="cellInnerDiv"] [data-testid="tweet"]`
);
for (const tweet of tweets) {
if (tweet.querySelector(`[data-testid="icon-verified"]`)) {
tweet.style.display = "none";
}
}
@jacob-ebey
jacob-ebey / event-delegation.ts
Last active September 28, 2023 06:53
Remix Event Delegation
import * as React from "react";
import { useNavigate, useSubmit } from "@remix-run/react";
export function useEventDelegation() {
const navigate = useNavigate();
const submit = useSubmit();
React.useEffect(() => {
const handleClick = (e: MouseEvent) => {
const target = e.target as HTMLElement;
if (
@jacob-ebey
jacob-ebey / fetch-server.d.ts
Created August 23, 2023 07:42
Node Fetch Server
import type { Server } from "node:http";
export type Handler = (request: Request) => Response | Promise<Response>;
export type CreateServerOptions = {
onError?: (error: unknown) => void;
};
export declare function createServer(
handler: Handler,
@jacob-ebey
jacob-ebey / example.js
Last active August 27, 2023 01:47
Webpack Federation Expose Remotes Plugin
const remote = () => "@app/" + "other";
__webpack_chunk_load__(remote()).then(async () => {
const container = __webpack_require__(remote());
const factory = await container.get("./federated");
const mod = factory();
console.log({
APP_NAME,
REMOTE: mod.name,
});
@jacob-ebey
jacob-ebey / recursive-rsc-stream-inline.ts
Last active March 25, 2024 07:05
Inline RSC stream with a recursive async component that is streamed as part of the SSR renderToXYZ call.
import * as React from "react";
// @ts-ignore
import * as ReactDOM from "#react-dom-server-implementation";
// @ts-ignore
import * as ReactDOMClient from "#react-server-dom-client-implementation";
export async function fetch(
request: Request,
{
browserEntry,