summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2023-02-13 14:48:36 -0500
committerGravatar GitHub <noreply@github.com> 2023-02-13 14:48:36 -0500
commita7f18051b118b4f263ed9093ab17ed7eec0e4fd5 (patch)
tree011e81b3a177ff9e2d9a5ac6f03b7d103a57d6d9
parentb46787c8ebbb45a7712a2d4d0bde7636d8c08eb3 (diff)
downloadastro-a7f18051b118b4f263ed9093ab17ed7eec0e4fd5.tar.gz
astro-a7f18051b118b4f263ed9093ab17ed7eec0e4fd5.tar.zst
astro-a7f18051b118b4f263ed9093ab17ed7eec0e4fd5.zip
Prevent hydration mismatches in Preact (#6215)
-rw-r--r--.changeset/orange-chicken-end.md5
-rw-r--r--packages/integrations/preact/src/client.ts14
2 files changed, 17 insertions, 2 deletions
diff --git a/.changeset/orange-chicken-end.md b/.changeset/orange-chicken-end.md
new file mode 100644
index 000000000..049120305
--- /dev/null
+++ b/.changeset/orange-chicken-end.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/preact': patch
+---
+
+Prevent hydration mismatches in Preact
diff --git a/packages/integrations/preact/src/client.ts b/packages/integrations/preact/src/client.ts
index 4549e79f4..6c7b99f76 100644
--- a/packages/integrations/preact/src/client.ts
+++ b/packages/integrations/preact/src/client.ts
@@ -1,4 +1,4 @@
-import { h, render } from 'preact';
+import { h, type JSX, render } from 'preact';
import StaticHtml from './static-html.js';
import type { SignalLike } from './types';
@@ -26,8 +26,18 @@ export default (element: HTMLElement) =>
props[propName] = sharedSignalMap.get(signalId);
}
}
+
+ // eslint-disable-next-line @typescript-eslint/no-shadow
+ function Wrapper({ children }: { children: JSX.Element }) {
+ let attrs = Object.fromEntries(Array.from(element.attributes).map(attr => [attr.name, attr.value]));
+ return h(element.localName, attrs, children);
+ }
+
render(
- h(Component, props, children != null ? h(StaticHtml, { value: children }) : children),
+ h(Wrapper, null,
+ h(Component, props, children != null ? h(StaticHtml, { value: children }) : children)
+ ),
+ element.parentNode!,
element
);
};