Open
Conversation
Run with `pnpm run test --config vitest.jsx-runtime.config.ts`
Can be used to set the "jsxImportSource" option using pragma directives at the top of test files, for example: ```tsx /** @jsxRuntime automatic */ /** @jsxImportSource #satori/jsx */ ```
Satori will call component functions and pass its props as args when calculating the layout of a sub-tree (see https://github.com/vercel/satori/blob/50a794813c2ea3fc15a168e0cd144078c7f69815/src/layout.ts#L96). This change also adds support for async custom components since Satori awaits the calls to component functions, we just have to update the types to reflect that. all the tests pass now btw
React typings use explicity `any` types and empty interfaces (so that users will be able to extend them).
Export all types and the `createElement()` function from this new module. This module is intended to be public and users should be able to import types and other helper functions from here.
Change the return type of the exported `jsx` function and extract the 'key' prop from props.
More featured `createElement()` function closer to the React implementation.
Adapted from v19.1; only the types and interfaces that are used for `JSX.IntrinsicElements` have been copied over.
Only an index signature has been specified.
From React typings package.
Adapted from React typings.
Using a relative import path since this old version of vitest doesn't appear to support Node's subpath imports (i.e., module specifiers that begin with "#"), but this creates problems for TypeScript. Using `/** @jsxImportSource #satori/jsx */` at the top of the file will make the TS errors go away, but will make vitest will fail to run the file. https://nodejs.org/docs/latest/api/packages.html#subpath-imports
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Also fix typo.
I noticed when manually inspecting the bundled declaration files, the
interfaces weren't being renamed according to how I was importing them
in the source file:
import type { IntrinsicElements as DefinedIntrinsicElements } from '...'
So the `IntrinsicElements` interface was recursively referencing itself
in the JSX namespace because it was all bundled together in the same
file.
So in an abundance of caution, I just renamed it just to be safe.
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Author
|
I figured that creating a custom subset of HTML/SVG/CSS types sounds like a lot of work and that it should probably be in a separate PR haha I’d love to hear what you think about this feature, and please let me know if there’s anything else I can help with! |
Member
|
Can you give some example use cases for this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JSX without installing React
Now we can write JSX for Satori without having to install React as a dependency. Just add a
@jsxImportSourcepragma directive at the top of your files.Types
The types are adapted from
@types/reactand include aJSX.IntrinsicElementsinterface for autocompleting HTML and SVG. Which means that it can be modified to only have the subset of elements and CSS properties supported by Satori for some beautiful autocomplete (but at that point I guess it wouldn't be a "minimal runtime" anymore).Testing
TODO
satori/jsx,satori/jsx/jsx-runtime, andsatori/jsx/jsx-dev-runtimeJSX.IntrinsicElements(if ya wanna do that)I've been sitting on this for a while so I'll update when I remember more stuff...
Thank you for maintaining this awesome project and checking out my PR!