From 7820096e1ba29ecc58aa7e13311a255acd2fe977 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Mon, 22 Aug 2022 11:46:02 -0400 Subject: [PATCH] fix: correctly add `react-dom` alias to Vercel edge (#4421) * fix: correctly add react-dom alias to vercel edge * chore: changeset --- .changeset/heavy-pants-change.md | 5 +++++ packages/integrations/vercel/src/edge/adapter.ts | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .changeset/heavy-pants-change.md diff --git a/.changeset/heavy-pants-change.md b/.changeset/heavy-pants-change.md new file mode 100644 index 000000000000..32c7b30efe1a --- /dev/null +++ b/.changeset/heavy-pants-change.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vercel': patch +--- + +Fix react-dom on Vercel edge diff --git a/packages/integrations/vercel/src/edge/adapter.ts b/packages/integrations/vercel/src/edge/adapter.ts index 84ecd7395265..14dac655d37e 100644 --- a/packages/integrations/vercel/src/edge/adapter.ts +++ b/packages/integrations/vercel/src/edge/adapter.ts @@ -32,8 +32,17 @@ export default function vercelEdge(): AstroIntegration { if (target === 'server') { vite.resolve ||= {}; vite.resolve.alias ||= {}; - const alias = vite.resolve.alias as Record; - alias['react-dom/server'] = 'react-dom/server.browser'; + + const aliases = [{ find: 'react-dom/server', replacement: 'react-dom/server.browser' }]; + + if (Array.isArray(vite.resolve.alias)) { + vite.resolve.alias = [...vite.resolve.alias, ...aliases]; + } else { + for (const alias of aliases) { + (vite.resolve.alias as Record)[alias.find] = alias.replacement; + } + } + vite.ssr = { noExternal: true, };