From db43d8ee6ab541370b4e70c4f156d6bf6d1137ae Mon Sep 17 00:00:00 2001 From: Belinda Cao Date: Wed, 31 Jul 2024 12:01:44 +0800 Subject: [PATCH] fix: react 17 ssr context error (#6023) --- .changeset/tasty-ads-rest.md | 7 +++++++ .../runtime/plugin-runtime/src/core/browser/hydrate.tsx | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/tasty-ads-rest.md diff --git a/.changeset/tasty-ads-rest.md b/.changeset/tasty-ads-rest.md new file mode 100644 index 000000000000..dfe343c05668 --- /dev/null +++ b/.changeset/tasty-ads-rest.md @@ -0,0 +1,7 @@ +--- +'@modern-js/runtime': patch +--- + +fix: react 17 ssr context error + +fix: 修复 react 17 ssr 找不到 runtimeReactContext 报错 diff --git a/packages/runtime/plugin-runtime/src/core/browser/hydrate.tsx b/packages/runtime/plugin-runtime/src/core/browser/hydrate.tsx index 0796f50bb732..d6b794b5d7c1 100644 --- a/packages/runtime/plugin-runtime/src/core/browser/hydrate.tsx +++ b/packages/runtime/plugin-runtime/src/core/browser/hydrate.tsx @@ -96,7 +96,10 @@ export function hydrateRoot( }); } else { loadableReady(() => { - ModernHydrate(App, callback).then(root => { + ModernHydrate( + React.cloneElement(App, { _internal_context: hydrateContext }), + callback, + ).then(root => { resolve(root); }); });