Skip to content

Commit 76d0e91

Browse files
authored
Merge branch 'main' into streaming-render-update
2 parents cbabc9e + e02629e commit 76d0e91

22 files changed

+510
-64
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- '**'
88
push:
99
branches:
10-
- master
10+
- main
1111

1212
jobs:
1313
build_test:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Release
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77

88
jobs:
99
release:

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
# preact-render-to-string
22

3+
## 6.2.0
4+
5+
### Minor Changes
6+
7+
- [#305](https://github.com/preactjs/preact-render-to-string/pull/305) [`568f139`](https://github.com/preactjs/preact-render-to-string/commit/568f139a6c7916e0b6eebb7c51f1abf035850b7c) Thanks [@marvinhagemeister](https://github.com/marvinhagemeister)! - Add support for error boundaries via `componentDidCatch` and `getDerivedStateFromError`
8+
9+
This feature is disabled by default and can be enabled by toggling the `errorBoundaries` option:
10+
11+
```js
12+
import { options } from 'preact';
13+
14+
// Enable error boundaries
15+
options.errorBoundaries = true;
16+
```
17+
18+
## 6.1.0
19+
20+
### Minor Changes
21+
22+
- [#301](https://github.com/preactjs/preact-render-to-string/pull/301) [`659b456`](https://github.com/preactjs/preact-render-to-string/commit/659b45623093ae0a93cb29354b069a25cf6351b5) Thanks [@marvinhagemeister](https://github.com/marvinhagemeister)! - Add experimental ability to render HTML comments via `<Fragment UNSTABLE_comment="my-comment" />`. When the `UNSTABLE_comment` prop is present all children of that `Fragment` will be ignored and a HTML comment will be rendered instead. This feature is added to allow framework authors to experiment with marking DOM for hydration in the client. Note that it's marked as unstable and might change in the future.
23+
24+
## 6.0.3
25+
26+
### Patch Changes
27+
28+
- [#298](https://github.com/preactjs/preact-render-to-string/pull/298) [`6a4b8ed`](https://github.com/preactjs/preact-render-to-string/commit/6a4b8edc3b60038d2dc539a9652db806c5c24616) Thanks [@shinyama-k](https://github.com/shinyama-k)! - Fix to add type file for jsx.js
29+
30+
## 6.0.2
31+
32+
### Patch Changes
33+
34+
- [#294](https://github.com/preactjs/preact-render-to-string/pull/294) [`637b302`](https://github.com/preactjs/preact-render-to-string/commit/637b3021ff05a0729a1a7c0eb965ce3fc3556af6) Thanks [@marvinhagemeister](https://github.com/marvinhagemeister)! - Bring back exports from 5.x to make migration easier
35+
36+
## 6.0.1
37+
38+
### Patch Changes
39+
40+
- [#292](https://github.com/preactjs/preact-render-to-string/pull/292) [`8f4692c`](https://github.com/preactjs/preact-render-to-string/commit/8f4692c49277591819acb74808a0e28f7cb30c2f) Thanks [@marvinhagemeister](https://github.com/marvinhagemeister)! - Fix error in commonjs entry point
41+
342
## 6.0.0
443

544
### Major Changes

README.md

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ app.get('/:fox', (req, res) => {
8484
});
8585
```
8686

87+
### Error Boundaries
88+
89+
Rendering errors can be caught by Preact via `getDerivedStateFromErrors` or `componentDidCatch`. To enable that feature in `preact-render-to-string` set `errorBoundaries = true`
90+
91+
```js
92+
import { options } from 'preact';
93+
94+
// Enable error boundaries in `preact-render-to-string`
95+
options.errorBoundaries = true;
96+
```
97+
8798
---
8899

89100
### `Suspense` & `lazy` components with [`preact/compat`](https://www.npmjs.com/package/preact) & [`preact-ssr-prepass`](https://www.npmjs.com/package/preact-ssr-prepass)
@@ -94,50 +105,48 @@ npm install preact preact-render-to-string preact-ssr-prepass
94105

95106
```jsx
96107
export default () => {
97-
return (
98-
<h1>Home page</h1>
99-
)
100-
}
108+
return <h1>Home page</h1>;
109+
};
101110
```
102111

103112
```jsx
104-
import { Suspense, lazy } from "preact/compat"
113+
import { Suspense, lazy } from 'preact/compat';
105114

106115
// Creation of the lazy component
107-
const HomePage = lazy(() => import("./pages/home"))
116+
const HomePage = lazy(() => import('./pages/home'));
108117

109118
const Main = () => {
110-
return (
111-
<Suspense fallback={<p>Loading</p>}>
112-
<HomePage />
113-
</Suspense>
114-
)
115-
}
119+
return (
120+
<Suspense fallback={<p>Loading</p>}>
121+
<HomePage />
122+
</Suspense>
123+
);
124+
};
116125
```
117126

118127
```jsx
119-
import { render } from "preact-render-to-string"
120-
import prepass from "preact-ssr-prepass"
121-
import { Main } from "./main"
128+
import { render } from 'preact-render-to-string';
129+
import prepass from 'preact-ssr-prepass';
130+
import { Main } from './main';
122131

123132
const main = async () => {
124-
// Creation of the virtual DOM
125-
const vdom = <Main />
126-
127-
// Pre-rendering of lazy components
128-
await prepass(vdom)
129-
130-
// Rendering of components
131-
const html = render(vdom)
132-
133-
console.log(html)
134-
// <h1>Home page</h1>
135-
}
133+
// Creation of the virtual DOM
134+
const vdom = <Main />;
135+
136+
// Pre-rendering of lazy components
137+
await prepass(vdom);
138+
139+
// Rendering of components
140+
const html = render(vdom);
141+
142+
console.log(html);
143+
// <h1>Home page</h1>
144+
};
136145

137146
// Execution & error handling
138-
main().catch(error => {
139-
console.error(error)
140-
})
147+
main().catch((error) => {
148+
console.error(error);
149+
});
141150
```
142151

143152
---

config/node-commonjs.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,23 @@ const filePath = (file) => path.join(process.cwd(), 'dist', file);
1010
fs.copyFileSync(filePath('index.js'), filePath('commonjs.js'));
1111
fs.copyFileSync(filePath('index.js.map'), filePath('commonjs.js.map'));
1212

13-
const source = `module.exports = require('./commonjs').default;`;
13+
const source = [
14+
`const mod = require('./commonjs');`,
15+
`mod.default.renderToStaticMarkup = mod.default;`,
16+
`mod.default.renderToString = mod.default;`,
17+
`mod.default.render = mod.default;`,
18+
`module.exports = mod.default;`
19+
].join('\n');
1420
fs.writeFileSync(filePath('index.js'), source, 'utf-8');
1521

1622
// JSX entry
1723
fs.copyFileSync(filePath('jsx.js'), filePath('jsx-entry.js'));
1824
fs.copyFileSync(filePath('jsx.js.map'), filePath('jsx-entry.js.map'));
1925

20-
const sourceJsx = `module.exports = require('./jsx-entry').default;`;
26+
const sourceJsx = [
27+
`const entry = require('./jsx-entry');`,
28+
`entry.default.render = entry.render;`,
29+
`entry.default.shallowRender = entry.shallowRender;`,
30+
`module.exports = entry.default;`
31+
].join('\n');
2132
fs.writeFileSync(filePath('jsx.js'), sourceJsx, 'utf-8');

config/node-verify-exports.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const path = require('path');
2+
const assert = require('assert/strict');
3+
4+
const filePath = (file) => path.join(process.cwd(), 'dist', file);
5+
6+
// Main CJS
7+
const mainCjs = require(filePath('index.js'));
8+
assert(typeof mainCjs === 'function');
9+
assert(typeof mainCjs.renderToString === 'function');
10+
assert(typeof mainCjs.renderToStaticMarkup === 'function');
11+
assert(typeof mainCjs.render === 'function');
12+
13+
// Main ESM
14+
(async () => {
15+
const mainESM = await import(filePath('index.mjs'));
16+
assert(typeof mainESM.default === 'function');
17+
assert(typeof mainESM.renderToString === 'function');
18+
assert(typeof mainESM.renderToStaticMarkup === 'function');
19+
assert(typeof mainESM.render === 'function');
20+
})();
21+
22+
// JSX CJS
23+
const jsxCjs = require(filePath('jsx.js'));
24+
assert(typeof jsxCjs === 'function');
25+
assert(typeof jsxCjs.render === 'function');
26+
assert(typeof jsxCjs.shallowRender === 'function');
27+
28+
// JSX ESM
29+
(async () => {
30+
const jsxESM = await import(filePath('jsx.mjs'));
31+
assert(typeof jsxESM.default === 'function');
32+
assert(typeof jsxESM.render === 'function');
33+
assert(typeof jsxESM.shallowRender === 'function');
34+
})();

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "preact-render-to-string",
33
"amdName": "preactRenderToString",
4-
"version": "6.0.0",
4+
"version": "6.2.0",
55
"description": "Render JSX to an HTML string, with support for Preact components.",
66
"main": "dist/index.js",
77
"umd:main": "dist/index.umd.js",
@@ -41,7 +41,7 @@
4141
"bench": "BABEL_ENV=test node -r @babel/register benchmarks index.js",
4242
"bench:v8": "BABEL_ENV=test microbundle benchmarks/index.js -f modern --alias benchmarkjs-pretty=benchmarks/lib/benchmark-lite.js --external none --target node --no-compress --no-sourcemap --raw -o benchmarks/.v8.mjs && v8 --module benchmarks/.v8.modern.js",
4343
"build": "npm run -s transpile && npm run -s transpile:jsx && npm run -s copy-typescript-definition",
44-
"postbuild": "node ./config/node-13-exports.js && node ./config/node-commonjs.js",
44+
"postbuild": "node ./config/node-13-exports.js && node ./config/node-commonjs.js && node ./config/node-verify-exports.js",
4545
"transpile": "microbundle src/index.js -f es,cjs,umd --target web --external preact",
4646
"transpile:jsx": "microbundle src/jsx.js -o dist/jsx.js --target web --external preact && microbundle dist/jsx.js -o dist/jsx.js -f cjs --external preact",
4747
"copy-typescript-definition": "copyfiles -f src/*.d.ts dist",
@@ -63,6 +63,7 @@
6363
"src",
6464
"dist",
6565
"jsx.js",
66+
"jsx.d.ts",
6667
"typings.json"
6768
],
6869
"eslintConfig": {

src/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
import { VNode } from 'preact';
22

33
export default function renderToString(vnode: VNode, context?: any): string;
4+
5+
export function render(vnode: VNode, context?: any): string;
6+
export function renderToString(vnode: VNode, context?: any): string;
7+
export function renderToStaticMarkup(vnode: VNode, context?: any): string;

0 commit comments

Comments
 (0)