forked from laptou/astro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add preact/compat renderer (likely broken) Based on the current Preact renderer and the old preact/compat implementation: https://github.com/withastro/astro/blob/f892aeb52f5a93d81a68d9833eb26bedd06aa2f0/packages/renderers/renderer-preact/compat/index.js * Make sure name is consistent * Switch to single integration with compat option * fix: add module-resolver to alias react => preact/compat * fix: preact/compat mode * chore: remove client-compat entrypoint * chore: add e2e test for preact/compat * Try to fix frozen lock file error * Add changeset * Update README to new structure & document `compat` * Fix changeset wording * Fix README typo * Tweak wording Co-authored-by: Kevin Zuniga Cuellar <46791833+kevinzunigacuellar@users.noreply.github.com> Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> Co-authored-by: Kevin Zuniga Cuellar <46791833+kevinzunigacuellar@users.noreply.github.com>
- Loading branch information
1 parent
c4cf5e7
commit 02733b1
Showing
9 changed files
with
144 additions
and
0 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,7 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import preact from '@astrojs/preact'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [preact({ compat: 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,10 @@ | ||
{ | ||
"name": "@e2e/preact-component", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@astrojs/preact": "workspace:*", | ||
"astro": "workspace:*", | ||
"preact": "^10.7.3" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
e2e/fixtures/preact-compat-component/src/components/Counter.css
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,11 @@ | ||
.counter { | ||
display: grid; | ||
font-size: 2em; | ||
grid-template-columns: repeat(3, minmax(0, 1fr)); | ||
margin-top: 2em; | ||
place-items: center; | ||
} | ||
|
||
.counter-message { | ||
text-align: center; | ||
} |
19 changes: 19 additions & 0 deletions
19
e2e/fixtures/preact-compat-component/src/components/Counter.jsx
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,19 @@ | ||
import { useState } from 'react'; | ||
import './Counter.css'; | ||
|
||
export default function Counter({ children, count: initialCount, id }) { | ||
const [count, setCount] = useState(initialCount); | ||
const add = () => setCount((i) => i + 1); | ||
const subtract = () => setCount((i) => i - 1); | ||
|
||
return ( | ||
<> | ||
<div id={id} className="counter"> | ||
<button className="decrement" onClick={subtract}>-</button> | ||
<pre>{count}</pre> | ||
<button className="increment" onClick={add}>+</button> | ||
</div> | ||
<div className="counter-message">{children}</div> | ||
</> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
e2e/fixtures/preact-compat-component/src/components/JSXComponent.jsx
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 @@ | ||
import React from 'react'; | ||
|
||
export default function({ id }) { | ||
return <div id={id}>Framework client:only component</div> | ||
} |
4 changes: 4 additions & 0 deletions
4
e2e/fixtures/preact-compat-component/src/components/Layout.astro
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,4 @@ | ||
<html> | ||
<head><title>Preact compat component</title></head> | ||
<body><slot></slot></body> | ||
</html> |
37 changes: 37 additions & 0 deletions
37
e2e/fixtures/preact-compat-component/src/pages/index.astro
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,37 @@ | ||
--- | ||
import Counter from '../components/Counter.jsx'; | ||
import PreactCompatComponent from '../components/JSXComponent.jsx'; | ||
const someProps = { | ||
count: 0, | ||
}; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<!-- Head Stuff --> | ||
</head> | ||
<body> | ||
<Counter id="server-only" {...someProps}> | ||
<h1>Hello, server!</h1> | ||
</Counter> | ||
|
||
<Counter id="client-idle" {...someProps} client:idle> | ||
<h1>Hello, client:idle!</h1> | ||
</Counter> | ||
|
||
<Counter id="client-load" {...someProps} client:load> | ||
<h1>Hello, client:load!</h1> | ||
</Counter> | ||
|
||
<Counter id="client-visible" {...someProps} client:visible> | ||
<h1>Hello, client:visible!</h1> | ||
</Counter> | ||
|
||
<Counter id="client-media" {...someProps} client:media="(max-width: 50em)"> | ||
<h1>Hello, client:media!</h1> | ||
</Counter> | ||
|
||
<PreactCompatComponent id="client-only" client:only="preact" /> | ||
</body> | ||
</html> |
32 changes: 32 additions & 0 deletions
32
e2e/fixtures/preact-compat-component/src/pages/markdown.md
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,32 @@ | ||
--- | ||
layout: ../components/Layout.astro | ||
setup: | | ||
import Counter from '../components/Counter.jsx'; | ||
import PreactComponent from '../components/JSXComponent.jsx'; | ||
const someProps = { | ||
count: 0, | ||
}; | ||
--- | ||
|
||
<Counter id="server-only" {...someProps}> | ||
# Hello, server! | ||
</Counter> | ||
|
||
<Counter id="client-idle" {...someProps} client:idle> | ||
# Hello, client:idle! | ||
</Counter> | ||
|
||
<Counter id="client-load" {...someProps} client:load> | ||
# Hello, client:load! | ||
</Counter> | ||
|
||
<Counter id="client-visible" {...someProps} client:visible> | ||
# Hello, client:visible! | ||
</Counter> | ||
|
||
<Counter id="client-media" {...someProps} client:media="(max-width: 50em)"> | ||
# Hello, client:media! | ||
</Counter> | ||
|
||
<PreactComponent id="client-only" client:only="preact" /> |
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,19 @@ | ||
import { prepareTestFactory } from './shared-component-tests.js'; | ||
|
||
const { test, createTests } = prepareTestFactory({ root: './fixtures/preact-compat-component/' }); | ||
|
||
test.describe('preact/compat components in Astro files', () => { | ||
createTests({ | ||
pageUrl: '/', | ||
pageSourceFilePath: './src/pages/index.astro', | ||
componentFilePath: './src/components/JSXComponent.jsx', | ||
}); | ||
}); | ||
|
||
test.describe('preact/compat components in Markdown files', () => { | ||
createTests({ | ||
pageUrl: '/markdown/', | ||
pageSourceFilePath: './src/pages/markdown.md', | ||
componentFilePath: './src/components/JSXComponent.jsx', | ||
}); | ||
}); |