Skip to content
This repository was archived by the owner on Nov 30, 2025. It is now read-only.

Commit 0a408eb

Browse files
authored
Fix withHydrate wrapped named exports (#149)
* chore: update scripts * fix: named exports when using withHydrate * chore: changeset * chore: add named-export example * fix: default export case * fix: issue with useGlobalState * fix: dynamic routes example * refactor: rename hydrate map plugin
1 parent fbc4de0 commit 0a408eb

File tree

18 files changed

+290
-71
lines changed

18 files changed

+290
-71
lines changed

.changeset/cool-geckos-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"microsite": patch
3+
---
4+
5+
Fix an issue where named exports would not be properly hydrated

.changeset/smooth-eyes-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"microsite": patch
3+
---
4+
5+
Fix bug where useGlobalState would cause builds to fail

examples/dynamic-routes/src/pages/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Index: FunctionalComponent<any> = ({ renderedAt }) => {
1515
<ul>
1616
{Array.from({ length: 5 }, (_, i) => (
1717
<li>
18-
<a href={`/posts/${i + 1}`}>Page {i + 1}</a>
18+
<a href={`./posts/${i + 1}`}>Page {i + 1}</a>
1919
</li>
2020
))}
2121
</ul>

examples/dynamic-routes/src/pages/posts/[id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const Index: FunctionalComponent<any> = ({ num }) => {
1717

1818
<p>
1919
Head to{" "}
20-
<a href={`/posts/${nextPage}`}>
20+
<a href={`./posts/${nextPage}`}>
2121
<code>/posts/{nextPage}</code>
2222
</a>
2323
</p>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@example/named-exports",
3+
"homepage": "/named-exports",
4+
"version": "0.0.0",
5+
"private": true,
6+
"type": "module",
7+
"scripts": {
8+
"start": "microsite",
9+
"build": "microsite build -- --debug-hydration",
10+
"serve": "microsite build -- --debug-hydration --serve"
11+
},
12+
"devDependencies": {
13+
"microsite": "1.2.1"
14+
}
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { resolve, join, dirname } from 'path';
2+
import { fileURLToPath } from 'url';
3+
4+
const workspaceRoot = resolve(join(dirname(fileURLToPath(import.meta.url)), '..', '..'));
5+
6+
export default {
7+
workspaceRoot
8+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { withHydrate } from "microsite/hydrate";
2+
3+
const DefaultComponent = () => (
4+
<h1>
5+
Hello <code>default</code>
6+
</h1>
7+
);
8+
const NamedComponentInternal = () => (
9+
<h1>
10+
Hello <code>named</code>
11+
</h1>
12+
);
13+
14+
export const NamedComponent = withHydrate(NamedComponentInternal, {
15+
method: "idle",
16+
});
17+
18+
export default withHydrate(DefaultComponent, { method: "idle" });
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { withHydrate } from "microsite/hydrate";
2+
3+
const DefaultComponent = () => (
4+
<h1>
5+
Hello <code>default</code>
6+
</h1>
7+
);
8+
9+
export default withHydrate(DefaultComponent, { method: "idle" });
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { withHydrate } from "microsite/hydrate";
2+
3+
const NamedComponentInternal = () => (
4+
<h1>
5+
Hello <code>named</code>
6+
</h1>
7+
);
8+
9+
export const NamedComponent = withHydrate(NamedComponentInternal, {
10+
method: "idle",
11+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { FunctionalComponent } from "preact";
2+
import { definePage } from "microsite/page";
3+
import { Head, seo } from "microsite/head";
4+
5+
import DefaultComponentA from "../components/default";
6+
import { NamedComponent as NamedComponentA } from "../components/named";
7+
import DefaultComponentB, {
8+
NamedComponent as NamedComponentB,
9+
} from "../components/default-and-named";
10+
11+
const Index: FunctionalComponent = () => {
12+
return (
13+
<>
14+
<Head>
15+
<seo.title>Named Exports</seo.title>
16+
</Head>
17+
18+
<main>
19+
<DefaultComponentA />
20+
<DefaultComponentB />
21+
22+
<NamedComponentA />
23+
<NamedComponentB />
24+
</main>
25+
</>
26+
);
27+
};
28+
29+
export default definePage(Index);

0 commit comments

Comments
 (0)