Skip to content

Instantly share code, notes, and snippets.

@JLarky
JLarky / out.txt
Created September 15, 2023 15:44
RSC suspense
View out.txt
delay 2004
delay 1003
delay2 1002
delay 1001
@JLarky
JLarky / what.md
Created September 14, 2023 01:05
Bun: Warning: Each child in a list should have a unique "key" prop.
View what.md

so we have tes.jsx:

export default function SearchField() {
  return (
    <form>
      <label>1</label>
      <input id="sidebar-search-input" />
    </form>
  );
@JLarky
JLarky / Next.md
Created September 3, 2023 01:02
Initializing Next.js project with different package managers
View Next.md

Comparing install speed with cached deps

image

lower is better

Data

NPM

@JLarky
JLarky / 0_README.md
Last active August 10, 2023 05:37
Does gzip help with hydration data in SSR? https://twitter.com/JLarky/status/1688337744752525312
View 0_README.md
-rw-r--r--  1 jlarky  wheel  22137 Aug  6 17:44 index.html.gz
-rw-r--r--  1 jlarky  wheel  19815 Aug  6 17:45 rest.html.gz
-rw-r--r--  1 jlarky  wheel   2347 Aug  6 17:46 script.html.gz

So

19815+2347 = 22162 vs

@JLarky
JLarky / STUFF.md
Last active July 24, 2023 06:37
Living dangerously (or safely) with HTMX
View STUFF.md

I created this demo :)

The main point is that it allows you to compare two apps, one is in React, one in HTMX. Then I introduce this concept of "hey, what if I wanted to store data in HTML or markdown or whatever instead of just text, how would I do that in HTMX? The main idea is that modern backend frameworks (in this case Astro) allow you to work with HTML pretty safely, but you still have to be careful with HTMX specifically because data- attributes are executable in HTMX 🫠, but I have an example how to workaround it as well :)

here are the shadow banned tweets :)

View notes.txt
<div title="hi">
<Suspense>
<ClientComponent prop={await 123}>
</Suspense>
</div>
<ClientRoot url="/" />
next 12: send from server to client: ["client.js", {url: '/'}]
^^
@JLarky
JLarky / 00_README.md
Last active December 1, 2023 02:14
useChildFormStatus
View 00_README.md

Why is useFormStatus always returning pending false?

So you are trying out that new fangled useFormStatus hook but it doesn't actually react to the status of your form?

Now you tried to Google it and all you get is RTFM "go read docs again". Because hook useFormStatus shows you the status of parent form, not a sibling one.

Let's explain that in English.

  • <form><Spinner></form> works
  • `` doesn't
@JLarky
JLarky / IsolateCSS.tsx
Last active July 10, 2023 09:23
How to use shadow dom to isolate CSS of React component https://twitter.com/JLarky/status/1657989891526123520
View IsolateCSS.tsx
export function IsolateCSS(props: { children: React.ReactNode }) {
const onceRef = useRef(false);
const [shadowRoot, setShadowRoot] = useState<ShadowRoot>();
const ref = useCallback((ref: HTMLDivElement | null) => {
if (ref && onceRef.current === false) {
onceRef.current = true;
setShadowRoot(ref.attachShadow({ mode: 'open' }));
}
}, []);
View page.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<script>
window.startClerk = async () => {
function formRedirect(){
const form = '<form method="get" action="" name="redirect"></form>';
@JLarky
JLarky / 01_t3Env.ts
Last active May 3, 2023 03:41
This is @t3-oss/env-core but if you don't want to send zod to client bundle (be careful, it's for Astro, not Next.js) https://twitter.com/JLarky/status/1653595995744395264
View 01_t3Env.ts
// src/t3Env.ts
import { createEnv, LooseOptions, StrictOptions } from '@t3-oss/env-core';
import { z, ZodType, ZodString } from 'zod';
function validateEnv<
TPrefix extends string,
TServer extends Record<string, ZodType> = NonNullable<unknown>,
TClient extends Record<string, ZodType> = NonNullable<unknown>
>(opts: LooseOptions<TPrefix, TServer, TClient> | StrictOptions<TPrefix, TServer, TClient>) {
return opts;