Skip to content

Commit 36d1df6

Browse files
committed
SSR support
1 parent 89df90f commit 36d1df6

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

package-lock.json

Lines changed: 10 additions & 10 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@atomico/react",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "",
55
"types": "./wrapper.d.ts",
66
"publishConfig": {
@@ -21,7 +21,7 @@
2121
"@types/react": "latest",
2222
"@web/dev-server-esbuild": "^0.2.12",
2323
"@web/test-runner": "^0.13.5",
24-
"atomico": "^1.51.0",
24+
"atomico": "^1.60.1",
2525
"husky": "^6.0.0",
2626
"preact": "^10.6.6",
2727
"react": "npm:@esm-bundle/react",
@@ -31,7 +31,7 @@
3131
},
3232
"peerDependencies": {
3333
"@types/react": "latest",
34-
"atomico": "^1.49.2",
34+
"atomico": "^1.60.1",
3535
"preact": "latest",
3636
"react": "latest"
3737
},

src/core/create-wrapper.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JSXElement } from "atomico";
1+
import { JSXElement, options, h } from "atomico";
22
import { DOMAttributes } from "react";
33

44
interface Props {
@@ -61,6 +61,8 @@ export const createWrapper =
6161
[[], [], { ref }]
6262
);
6363

64+
useLayoutEffect = options.ssr ? () => {} : useLayoutEffect;
65+
6466
useLayoutEffect(() => {
6567
const { current } = ref;
6668
const unlisteners = handlers
@@ -77,6 +79,13 @@ export const createWrapper =
7779

7880
if (is) nextProps.is = tagName;
7981

82+
if (options.ssr) {
83+
nextProps.dangerouslySetInnerHTML = {
84+
//@ts-ignore
85+
__html: h(base).render().innerHTML,
86+
};
87+
nextProps["data-hydrate"] = "";
88+
}
8089
return createElement(is || tagName, nextProps, children);
8190
}
8291
) as Component<Base>;

0 commit comments

Comments
 (0)