mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
feat: updates to server render react 19 correctly
This commit is contained in:
parent
9a31940a43
commit
464e4bfeaf
3 changed files with 11 additions and 20 deletions
|
@ -62,8 +62,8 @@
|
|||
"peerDependencies": {
|
||||
"@types/react": "^17.0.50 || ^18.0.21",
|
||||
"@types/react-dom": "^17.0.17 || ^18.0.6",
|
||||
"react": "^17.0.2 || ^18.0.0",
|
||||
"react-dom": "^17.0.2 || ^18.0.0"
|
||||
"react": "^17.0.2 || ^18.0.0 || ^19.0.0",
|
||||
"react-dom": "^17.0.2 || ^18.0.0 || ^19.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import opts from 'astro:react:opts';
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/server';
|
||||
import ReactDOM from 'react-dom/server.browser';
|
||||
import { incrementId } from './context.js';
|
||||
import StaticHtml from './static-html.js';
|
||||
|
||||
|
|
|
@ -10,17 +10,14 @@ export type ReactIntegrationOptions = Pick<
|
|||
experimentalReactChildren?: boolean;
|
||||
};
|
||||
|
||||
const isLegacy = ReactVersion.startsWith('17.');
|
||||
const FAST_REFRESH_PREAMBLE = react.preambleCode;
|
||||
|
||||
function getRenderer() {
|
||||
return {
|
||||
name: '@astrojs/react',
|
||||
clientEntrypoint: ReactVersion.startsWith('18.')
|
||||
? '@astrojs/react/client.js'
|
||||
: '@astrojs/react/client-v17.js',
|
||||
serverEntrypoint: ReactVersion.startsWith('18.')
|
||||
? '@astrojs/react/server.js'
|
||||
: '@astrojs/react/server-v17.js',
|
||||
clientEntrypoint: isLegacy ? '@astrojs/react/client-v17.js' : '@astrojs/react/client.js',
|
||||
serverEntrypoint: isLegacy ? '@astrojs/react/server-v17.js' : '@astrojs/react/server.js',
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -55,28 +52,22 @@ function getViteConfiguration({
|
|||
return {
|
||||
optimizeDeps: {
|
||||
include: [
|
||||
ReactVersion.startsWith('18.')
|
||||
? '@astrojs/react/client.js'
|
||||
: '@astrojs/react/client-v17.js',
|
||||
isLegacy ? '@astrojs/react/client-v17.js' : '@astrojs/react/client.js',
|
||||
'react',
|
||||
'react/jsx-runtime',
|
||||
'react/jsx-dev-runtime',
|
||||
'react-dom',
|
||||
],
|
||||
exclude: [
|
||||
ReactVersion.startsWith('18.')
|
||||
? '@astrojs/react/server.js'
|
||||
: '@astrojs/react/server-v17.js',
|
||||
],
|
||||
exclude: [isLegacy ? '@astrojs/react/server-v17.js' : '@astrojs/react/server.js'],
|
||||
},
|
||||
plugins: [react({ include, exclude, babel }), optionsPlugin(!!experimentalReactChildren)],
|
||||
resolve: {
|
||||
dedupe: ['react', 'react-dom', 'react-dom/server'],
|
||||
},
|
||||
ssr: {
|
||||
external: ReactVersion.startsWith('18.')
|
||||
? ['react-dom/server', 'react-dom/client']
|
||||
: ['react-dom/server.js', 'react-dom/client.js'],
|
||||
external: isLegacy
|
||||
? ['react-dom/server.js', 'react-dom/client.js']
|
||||
: ['react-dom/server', 'react-dom/client'],
|
||||
noExternal: [
|
||||
// These are all needed to get mui to work.
|
||||
'@mui/material',
|
||||
|
|
Loading…
Reference in a new issue