fix: correctly add react-dom alias to Vercel edge (#4421)

* fix: correctly add react-dom alias to vercel edge

* chore: changeset
This commit is contained in:
Ben Holmes 2022-08-22 11:46:02 -04:00 committed by GitHub
parent 39088e11db
commit 7820096e1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---
Fix react-dom on Vercel edge

View file

@ -32,8 +32,17 @@ export default function vercelEdge(): AstroIntegration {
if (target === 'server') {
vite.resolve ||= {};
vite.resolve.alias ||= {};
const alias = vite.resolve.alias as Record<string, string>;
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<string, string>)[alias.find] = alias.replacement;
}
}
vite.ssr = {
noExternal: true,
};