Skip to content

[DRAFT] HTML-in-Canvas demos - #290

Draft
uuuulala wants to merge 31 commits into
mainfrom
html-in-canvas
Draft

uuuulala wants to merge 31 commits into
mainfrom
html-in-canvas

Conversation

@uuuulala

Copy link
Copy Markdown
Member

No description provided.

@vercel

vercel Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
shaders-docs Ready Ready Preview Oct 11, 2026 12:34pm UTC

Request Review

import { captureHtmlImage } from '@paper-design/shaders';

export function hasChildren(children: React.ReactNode): boolean {
return Children.toArray(children).length > 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we can just use Children.count(children) here (and then inline it because the intermediate function isnt needed)

export const HtmlCanvas: React.ForwardRefExoticComponent<HtmlCanvasProps & React.RefAttributes<HTMLDivElement>> =
forwardRef<HTMLDivElement, HtmlCanvasProps>(function HtmlCanvasImpl({ children }, ref) {
return (
<canvas {...{ layoutsubtree: '' }}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi this is changing to content="drawable" WICG/html-in-canvas#179 so would need to support both that + layoutsubtree

anywhere we can be backwards + forwards compatible the better

also make a types file html-in-canvas.d.ts and get your agent to define the types so it doesnt have to work around types not existing by spreading an object


/** A `<canvas layoutsubtree>` that lays out its children so they can be captured into shader textures */
export const HtmlCanvas: React.ForwardRefExoticComponent<HtmlCanvasProps & React.RefAttributes<HTMLDivElement>> =
forwardRef<HTMLDivElement, HtmlCanvasProps>(function HtmlCanvasImpl({ children }, ref) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forward ref isn't needed anymore, just pass ref as prop

}

/** A `<canvas layoutsubtree>` that lays out its children so they can be captured into shader textures */
export const HtmlCanvas: React.ForwardRefExoticComponent<HtmlCanvasProps & React.RefAttributes<HTMLDivElement>> =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: im a fan of calling things like HTMLCanvas rather than Html. since it's about capturing could also do HTMLCanvasCapture

children?: React.ReactNode;
}

/** A `<canvas layoutsubtree>` that lays out its children so they can be captured into shader textures */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to do anything to make sure hit testing works? e.g. if people want to put live elements into one of our shaders

isEnabled: boolean,
processImage: (url: string) => Promise<Blob>
): string | undefined {
const [processedUrl, setProcessedUrl] = useState<string>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would this look like if we didn't need to set state to pass on new image data? or is this mainly the preprocessing for logo shaders?

e.g. either every frame the shader is running, or when the html children change on the paint event, we pull or push the image data?

}

/** A `<canvas layoutsubtree>` that lays out its children so they can be captured into shader textures */
export const HtmlCanvas: React.ForwardRefExoticComponent<HtmlCanvasProps & React.RefAttributes<HTMLDivElement>> =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would also recommend us testing out using browser() from the new react 19.3 api https://react.dev/blog/2026/09/09/react-19-3#browser

lets us ensure components only run on the browser. on the server they suspend.

This branch was successfully deployed

1 active deployment
Preview — b6b12d50 Deployed Oct 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants