Registry / web-framework / jsx-async-runtime

jsx-async-runtime

JSON →
library2.1.1jsnpmunverified

An asynchronous JSX runtime for server-side rendering (SSR) and browser HTML template generation, with zero dependencies. Version 2.1.1 is current, with stable releases. Key differentiators: supports async components natively, automatic HTML entity escaping (v2+) for XSS prevention, and works with TypeScript, esbuild, and Babel via the react-jsx transform.

npm install jsx-async-runtime
INSTALL
IMPORT
SIG · JSX-ASYNC-RUNTIME
J
jsx-async-runtime
web-frameworkjavascriptv2.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

jsxToString
import { jsxToString } from 'jsx-async-runtime'
const { jsxToString } = require('jsx-async-runtime')
ESM-only; CJS require will not work in v2+.
escapeEntities
import { escapeEntities } from 'jsx-async-runtime'
import escapeEntities from 'jsx-async-runtime'
Named export, not default.
JSX namespace
import type { JSX } from 'jsx-async-runtime'
import { JSX } from 'jsx-async-runtime'
JSX is a type-only export; use `import type` in TypeScript.

Renders a basic HTML page with an async JSX component, using jsxToString with a 'this' context.

import { jsxToString } from 'jsx-async-runtime'; function HelloWorld({ greeting }) { return ( <> {{ html: '<!DOCTYPE html>' }} <html> <head> <meta charset="utf-8" /> <title>{greeting}</title> </head> <body> <h1>{greeting}</h1> </body> </html> </> ); } console.log(await jsxToString.call({}, <HelloWorld greeting="Hello World" />));
Debug
Known issues
breakingVersion 2.x escapes HTML entities by default, breaking raw HTML insertion from v1.
fix
Use the `{ html: '...' }` object pattern to insert raw HTML, or set `this.jsxEscapeHTML = false` to restore v1 behavior.
affects: >=2.0.0
gotchajsxToString requires `call({}, ...)` to provide a `this` context; calling it directly will fail.
fix
Call `jsxToString.call({}, element)` or pass a context object with `jsxEscapeHTML` and other options.
affects: >=1.0.0
gotchaAsync components must return JSX; returning a Promise that resolves to JSX is not supported.
fix
Use `async function` components that `await` and then return JSX directly.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'jsx-async-runtime'
Package not installed or import path incorrect.
fix
Ensure `npm i jsx-async-runtime` is run and use `import { jsxToString } from 'jsx-async-runtime'`.
TypeError: Cannot read properties of undefined (reading 'jsxEscapeHTML')
Calling jsxToString without a `this` context.
fix
Use `jsxToString.call({}, element)` instead of `jsxToString(element)`.
Warning: You are using the nonstandard "react-jsx" JSX transform
TypeScript compilerOptions not set correctly.
fix
Set `"jsx": "react-jsx", "jsxImportSource": "jsx-async-runtime"` in tsconfig.json.
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
jsx-async-runtime — npm install jsx-async-runtime · libregistry