-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose JSX compilation to renderers (#588)
* feat: add support for `jsxImportSource`, new JSX transform * Renderer: add Solid renderer (#667) * feat: add support for `jsxImportSource`, new JSX transform * WIP: solid renderer * [Renderer] Solid (#656) * feat: add support for `jsxImportSource`, new JSX transform * WIP: solid renderer * Solid renderer: fix SSR of children, hydration (top level) Caveat: cannot hydrate children/descendants of hydrated parents * Fix hydration of fragments * fix: SyntaxError in React/Preact renderers * fix: errors in React/Preact renderers * feat: update react external * chore: update examples * chore: delete old changelog * chore: update astro config Co-authored-by: Nate Moore <nate@skypack.dev> * Changing the preact to Solid (#669) * chore: use new client:visible syntax * fix: dev script issue * chore: cleanup SolidJS example * docs: update framework example docs * chore: cleanup framework-multiple example * fix: remove SolidJS false-positives from Preact renderer * chore: add changeset Co-authored-by: eyelidlessness <eyelidlessness@users.noreply.github.com> Co-authored-by: Abdullah Mzaien <s201540830@kfupm.edu.sa> * feat(create-astro): add Solid support * docs: add JSX options to renderer reference * chore: add changeset for P/React renderers * fix: move react/server.js to external * chore: remove brewfile * Revert "feat: add support for `jsxImportSource`, new JSX transform" This reverts commit 077c4bf. * fix: remove `react-dom/server` from `external` * chore: remove unused dependency * feat: improve JSX error messages * Revert "Revert "feat: add support for `jsxImportSource`, new JSX transform"" This reverts commit f6c2896. * docs: update jsxImportSource * feat: improve error message * feat: improve error logging for JSX renderers * tests: add jsx-runtime tests * chore: update snowpack Co-authored-by: eyelidlessness <eyelidlessness@users.noreply.github.com> Co-authored-by: Abdullah Mzaien <s201540830@kfupm.edu.sa>
- Loading branch information
1 parent
5ec97e6
commit b0157a5
Showing
46 changed files
with
2,943 additions
and
2,415 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/renderer-solid': minor | ||
--- | ||
|
||
Initial release |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@astrojs/renderer-preact': minor | ||
'@astrojs/renderer-react': minor | ||
--- | ||
|
||
Switches to [the new JSX Transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) originally introduced for React v17. This also leverages the new `jsxTransformOptions` options for renderers. | ||
|
||
This change also removes the need for importing your Framework's `jsxFactory` directly, which means you can wave goodbye to `import React from "react";` and `import { h } from "preact";`. | ||
|
||
> **If you are using mutliple frameworks** and a file doesn't reference `react` or `preact`, Astro might not be able to locate the correct renderer! You can add a pragma comment like `/** @jsxImportSource preact */` to the top of your file. Alternatively, just import the JSX pragma as you traditionally would have. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'create-astro': patch | ||
--- | ||
|
||
Add support for [Solid](https://www.solidjs.com/) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/renderer-preact': patch | ||
--- | ||
|
||
Update `check` logic to exclude false-positives from SolidJS |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** @jsxImportSource preact */ | ||
|
||
/** a counter written in Preact */ | ||
export default function PreactSFC({ children }) { | ||
return ( | ||
<> | ||
<div className="counter"> | ||
Hello from Preact! | ||
</div> | ||
</> | ||
); | ||
} |
This file contains 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
21 changes: 21 additions & 0 deletions
21
examples/framework-multiple/src/components/SolidCounter.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createSignal } from "solid-js"; | ||
|
||
/** a counter written with Solid */ | ||
export default function SolidCounter({ children }) { | ||
const [count, setCount] = createSignal(0); | ||
const add = () => setCount(count() + 1); | ||
const subtract = () => setCount(count() - 1); | ||
|
||
return ( | ||
<> | ||
<div id="solid" class="counter"> | ||
<button onClick={subtract}>-</button> | ||
<pre>{count()}</pre> | ||
<button onClick={add}>+</button> | ||
</div> | ||
<div class="children"> | ||
{children} | ||
</div> | ||
</> | ||
); | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
# Using Preact with Astro | ||
|
||
``` | ||
This example showcases Astro's built-in support for [Preact](https://www.preactjs.com/). | ||
|
||
## Installation | ||
|
||
### Automatic | ||
|
||
Bootstrap your Astro project with this template! | ||
|
||
```shell | ||
npm init astro -- --template framework-preact | ||
``` | ||
|
||
This example showcases Astro's built-in support for [Preact](https://preactjs.com/). | ||
### Manual | ||
|
||
To use Preact components in your Astro project: | ||
|
||
1. Install `@astrojs/renderer-preact` | ||
|
||
```shell | ||
npm i @astrojs/renderer-preact | ||
``` | ||
|
||
2. Add `"@astrojs/renderer-preact"` to your `renderers` in `astro.config.mjs`. | ||
|
||
```js | ||
export default { | ||
renderers: [ | ||
"@astrojs/renderer-preact", | ||
// optionally, others... | ||
] | ||
} | ||
``` | ||
|
||
No configuration is needed to enable Preact support—just start writing Preact components in `src/components`. | ||
## Usage | ||
|
||
> **Note**: If used, components _must_ include the JSX factory (ex. `import { h } from "preact"`). Astro is unable to determine which framework is used without having the [JSX factory](https://mariusschulz.com/blog/per-file-jsx-factories-in-typescript#what-is-a-jsx-factory) in scope. | ||
Write your Preact components as `.jsx` or `.tsx` files in your project. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
# Using React with Astro | ||
|
||
``` | ||
This example showcases Astro's built-in support for [React](https://reactjs.org/). | ||
|
||
## Installation | ||
|
||
### Automatic | ||
|
||
Bootstrap your Astro project with this template! | ||
|
||
```shell | ||
npm init astro -- --template framework-react | ||
``` | ||
|
||
This example showcases Astro's built-in support for [React](https://reactjs.org/). | ||
### Manual | ||
|
||
To use React components in your Astro project: | ||
|
||
1. Install `@astrojs/renderer-react` | ||
|
||
```shell | ||
npm i @astrojs/renderer-react | ||
``` | ||
|
||
2. Add `"@astrojs/renderer-react"` to your `renderers` in `astro.config.mjs`. | ||
|
||
```js | ||
export default { | ||
renderers: [ | ||
"@astrojs/renderer-react", | ||
// optionally, others... | ||
] | ||
} | ||
``` | ||
|
||
No configuration is needed to enable React support—just start writing React components in `src/components`. | ||
## Usage | ||
|
||
> **Note**: If used, components _must_ include the JSX factory (ex. `import React from "react"`). Astro is unable to determine which framework is used without having the [JSX factory](https://mariusschulz.com/blog/per-file-jsx-factories-in-typescript#what-is-a-jsx-factory) in scope. | ||
Write your React components as `.jsx` or `.tsx` files in your project. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# build output | ||
dist | ||
|
||
# dependencies | ||
node_modules/ | ||
.snowpack/ | ||
|
||
# logs | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# environment variables | ||
.env | ||
.env.production | ||
|
||
# macOS-specific files | ||
.DS_Store |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## force pnpm to hoist | ||
shamefully-hoist = true |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Using Solid with Astro | ||
|
||
This example showcases Astro's built-in support for [Solid](https://www.solidjs.com/). | ||
|
||
## Installation | ||
|
||
### Automatic | ||
|
||
Bootstrap your Astro project with this template! | ||
|
||
```shell | ||
npm init astro --template framework-solid | ||
``` | ||
|
||
### Manual | ||
|
||
To use Solid components in your Astro project: | ||
|
||
1. Install `@astrojs/renderer-solid` | ||
|
||
```shell | ||
npm i @astrojs/renderer-solid | ||
``` | ||
|
||
2. Add `"@astrojs/renderer-solid"` to your `renderers` in `astro.config.mjs`. | ||
|
||
```js | ||
export default { | ||
renderers: [ | ||
"@astrojs/renderer-solid", | ||
// optionally, others... | ||
] | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
Write your Solid components as `.jsx` or `.tsx` files in your project. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default { | ||
// projectRoot: '.', // Where to resolve all URLs relative to. Useful if you have a monorepo project. | ||
// pages: './src/pages', // Path to Astro components, pages, and data | ||
// dist: './dist', // When running `astro build`, path to final static output | ||
// public: './public', // A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that don’t need processing. | ||
buildOptions: { | ||
// site: 'http://example.com', // Your public domain, e.g.: https://my-site.dev/. Used to generate sitemaps and canonical URLs. | ||
// sitemap: true, // Generate sitemap (set to "false" to disable) | ||
}, | ||
devOptions: { | ||
// port: 3000, // The port to run the dev server on. | ||
// tailwindConfig: '', // Path to tailwind.config.js if used, e.g. './tailwind.config.js' | ||
}, | ||
renderers: [ | ||
'@astrojs/renderer-solid' | ||
] | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@example/framework-solid", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"start": "astro dev", | ||
"build": "astro build" | ||
}, | ||
"devDependencies": { | ||
"astro": "^0.18.0-next.1", | ||
"@astrojs/renderer-solid": "0.0.1" | ||
}, | ||
"snowpack": { | ||
"workspaceRoot": "../.." | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createSignal } from "solid-js"; | ||
|
||
/** */ | ||
export default function SolidCounter({ children }) { | ||
const [count, setCount] = createSignal(0); | ||
const add = () => setCount(count() + 1); | ||
const subtract = () => setCount(count() - 1); | ||
|
||
return ( | ||
<> | ||
<div class="counter"> | ||
<button onClick={subtract}>-</button> | ||
<pre>{count()}</pre> | ||
<button onClick={add}>+</button> | ||
</div> | ||
<div class="children"> | ||
{children} | ||
</div> | ||
</> | ||
); | ||
} |
Oops, something went wrong.