Skip to content

Commit 32ed202

Browse files
fix
1 parent ca3134c commit 32ed202

2 files changed

Lines changed: 21 additions & 25 deletions

File tree

packages/fresh/src/runtime/client/preact_hooks_client.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,29 @@ function WrappedHead(
6464
}
6565

6666
applyProps(props, matched);
67-
}, []);
67+
}, [originalType, props, key]);
6868

6969
if (enabled) {
7070
return null;
71+
} else {
72+
const inner = h(originalType, props);
73+
PATCHED.add(inner);
74+
return inner;
7175
}
72-
73-
const inner = h(originalType, props);
74-
PATCHED.add(inner);
75-
return inner;
7676
}
7777

7878
const oldVNodeHook = options.vnode;
7979
options.vnode = (vnode) => {
8080
assetHashingHook(vnode, BUILD_ID);
8181

82-
if (typeof vnode.type === "string") {
82+
const originalType = vnode.type;
83+
if (typeof originalType === "string") {
8384
if (CLIENT_NAV_ATTR in vnode.props) {
8485
const value = vnode.props[CLIENT_NAV_ATTR];
8586
if (typeof value === "boolean") {
8687
vnode.props[CLIENT_NAV_ATTR] = String(value);
8788
}
88-
}
89-
}
90-
91-
const originalType = vnode.type;
92-
93-
if (typeof originalType === "string") {
94-
if (!PATCHED.has(vnode)) {
89+
} else if (!PATCHED.has(vnode)) {
9590
switch (originalType) {
9691
case "title":
9792
case "meta":
@@ -100,14 +95,19 @@ options.vnode = (vnode) => {
10095
case "style":
10196
case "base":
10297
case "noscript":
103-
case "template":
104-
vnode = h(WrappedHead, {
98+
case "template": {
99+
// deno-lint-ignore no-explicit-any
100+
const v = vnode as VNode<any>;
101+
const props = vnode.props;
102+
const key = vnode.key;
103+
v.type = WrappedHead;
104+
v.props = {
105105
originalType,
106-
props: vnode.props,
107-
key: vnode.key,
108-
// deno-lint-ignore no-explicit-any
109-
}) as any;
106+
props,
107+
key,
108+
};
110109
break;
110+
}
111111
}
112112
}
113113
}

packages/fresh/tests/head_test.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
buildProd,
55
parseHtml,
66
waitFor,
7+
waitForText,
78
withBrowserApp,
89
} from "./test_utils.tsx";
910
import { expect } from "@std/expect";
@@ -171,12 +172,7 @@ Deno.test({
171172
await page.locator(".ready").wait();
172173
await page.locator("button").click();
173174

174-
await waitFor(async () => {
175-
const title = await page.evaluate(() => document.title);
176-
// deno-lint-ignore no-console
177-
console.log({ title });
178-
return title === "Count: 1";
179-
});
175+
await waitForText(page, "title", "Count: 1");
180176
});
181177
},
182178
sanitizeOps: false,

0 commit comments

Comments
 (0)