Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a static JSX transform option #14680

Open
aquapi opened this issue Oct 19, 2024 · 1 comment
Open

Add a static JSX transform option #14680

aquapi opened this issue Oct 19, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@aquapi
Copy link
Contributor

aquapi commented Oct 19, 2024

What is the problem this feature would solve?

This feature will add a faster way to transform JSX to string on the server-side, Similar to Deno precompile JSX

What is the feature you are proposing to solve the problem?

A jsx transform option to convert JSX to array templates similar to Deno precompile feature

What alternatives have you considered?

Right now the fastest way to render jsx to string on the server is by using kitajs/html, but it uses react-jsx transform which is a lot slower and requires more code then the method above

@aquapi aquapi added the enhancement New feature or request label Oct 19, 2024
@aquapi
Copy link
Contributor Author

aquapi commented Oct 19, 2024

Here's an example of how the compilation result should look like:

const text = Math.random() < 0.5 ? 'Hi' : 'Hello';
const element = <p class='text' id={text}>{text}</p>;

And an option somewhere (maybe tsconfig.json) that specifies:

{
  "jsx": "precompile",
  "jsxImportSource": "preact"
}
import { jsxTemplate, jsxEscape, jsxAttr } from 'preact/jsx-runtime';

// Store the template static parts
var tmpl = ['<p class="text" ', '>', '</p>'];

const text = Math.random() < 0.5 ? 'Hi' : 'Hello';
const element = jsxTemplate(tmpl, jsxAttr('id', text), jsxEscape(text));

Here's the details from Deno: https://deno.com/blog/v1.38#fastest-jsx-transform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant