-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: React - Use "createRoot" instead of "hydrateRoot" for `client:on…
…ly` (#3337) * feat: pass "client" directive to clientEntrypoints * refactor: remove hydration warning suppression react 17 * feat: remove hydration warning suppression react 18 * chore: changeset * fix: change metadata to options bag
- Loading branch information
1 parent
13e697f
commit 678c2b7
Showing
4 changed files
with
34 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'astro': patch | ||
'@astrojs/react': patch | ||
--- | ||
|
||
Fix: remove hydration failures on React v18 by exposing the "client" directive from Astro core. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { createElement } from 'react'; | ||
import { hydrate } from 'react-dom'; | ||
import { render, hydrate } from 'react-dom'; | ||
import StaticHtml from './static-html.js'; | ||
|
||
export default (element) => (Component, props, children) => | ||
hydrate( | ||
createElement( | ||
export default (element) => (Component, props, children, { client }) => | ||
{ | ||
const componentEl = createElement( | ||
Component, | ||
{ ...props, suppressHydrationWarning: true }, | ||
props, | ||
children != null | ||
? createElement(StaticHtml, { value: children, suppressHydrationWarning: true }) | ||
? createElement(StaticHtml, { value: children }) | ||
: children | ||
), | ||
element | ||
); | ||
); | ||
if (client === 'only') { | ||
return render(componentEl, element); | ||
} | ||
return hydrate(componentEl, element); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { createElement } from 'react'; | ||
import { hydrateRoot } from 'react-dom/client'; | ||
import { createRoot, hydrateRoot } from 'react-dom/client'; | ||
import StaticHtml from './static-html.js'; | ||
|
||
export default (element) => (Component, props, children) => | ||
hydrateRoot( | ||
element, | ||
createElement( | ||
export default (element) => (Component, props, children, { client }) => | ||
{ | ||
const componentEl = createElement( | ||
Component, | ||
{ ...props, suppressHydrationWarning: true }, | ||
props, | ||
children != null | ||
? createElement(StaticHtml, { value: children, suppressHydrationWarning: true }) | ||
? createElement(StaticHtml, { value: children }) | ||
: children | ||
) | ||
); | ||
); | ||
if (client === 'only') { | ||
return createRoot(element).render(componentEl); | ||
} | ||
return hydrateRoot(element, componentEl); | ||
}; |