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": {
|
"peerDependencies": {
|
||||||
"@types/react": "^17.0.50 || ^18.0.21",
|
"@types/react": "^17.0.50 || ^18.0.21",
|
||||||
"@types/react-dom": "^17.0.17 || ^18.0.6",
|
"@types/react-dom": "^17.0.17 || ^18.0.6",
|
||||||
"react": "^17.0.2 || ^18.0.0",
|
"react": "^17.0.2 || ^18.0.0 || ^19.0.0",
|
||||||
"react-dom": "^17.0.2 || ^18.0.0"
|
"react-dom": "^17.0.2 || ^18.0.0 || ^19.0.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
|
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import opts from 'astro:react:opts';
|
import opts from 'astro:react:opts';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom/server';
|
import ReactDOM from 'react-dom/server.browser';
|
||||||
import { incrementId } from './context.js';
|
import { incrementId } from './context.js';
|
||||||
import StaticHtml from './static-html.js';
|
import StaticHtml from './static-html.js';
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,14 @@ export type ReactIntegrationOptions = Pick<
|
||||||
experimentalReactChildren?: boolean;
|
experimentalReactChildren?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isLegacy = ReactVersion.startsWith('17.');
|
||||||
const FAST_REFRESH_PREAMBLE = react.preambleCode;
|
const FAST_REFRESH_PREAMBLE = react.preambleCode;
|
||||||
|
|
||||||
function getRenderer() {
|
function getRenderer() {
|
||||||
return {
|
return {
|
||||||
name: '@astrojs/react',
|
name: '@astrojs/react',
|
||||||
clientEntrypoint: ReactVersion.startsWith('18.')
|
clientEntrypoint: isLegacy ? '@astrojs/react/client-v17.js' : '@astrojs/react/client.js',
|
||||||
? '@astrojs/react/client.js'
|
serverEntrypoint: isLegacy ? '@astrojs/react/server-v17.js' : '@astrojs/react/server.js',
|
||||||
: '@astrojs/react/client-v17.js',
|
|
||||||
serverEntrypoint: ReactVersion.startsWith('18.')
|
|
||||||
? '@astrojs/react/server.js'
|
|
||||||
: '@astrojs/react/server-v17.js',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,28 +52,22 @@ function getViteConfiguration({
|
||||||
return {
|
return {
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
include: [
|
include: [
|
||||||
ReactVersion.startsWith('18.')
|
isLegacy ? '@astrojs/react/client-v17.js' : '@astrojs/react/client.js',
|
||||||
? '@astrojs/react/client.js'
|
|
||||||
: '@astrojs/react/client-v17.js',
|
|
||||||
'react',
|
'react',
|
||||||
'react/jsx-runtime',
|
'react/jsx-runtime',
|
||||||
'react/jsx-dev-runtime',
|
'react/jsx-dev-runtime',
|
||||||
'react-dom',
|
'react-dom',
|
||||||
],
|
],
|
||||||
exclude: [
|
exclude: [isLegacy ? '@astrojs/react/server-v17.js' : '@astrojs/react/server.js'],
|
||||||
ReactVersion.startsWith('18.')
|
|
||||||
? '@astrojs/react/server.js'
|
|
||||||
: '@astrojs/react/server-v17.js',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
plugins: [react({ include, exclude, babel }), optionsPlugin(!!experimentalReactChildren)],
|
plugins: [react({ include, exclude, babel }), optionsPlugin(!!experimentalReactChildren)],
|
||||||
resolve: {
|
resolve: {
|
||||||
dedupe: ['react', 'react-dom', 'react-dom/server'],
|
dedupe: ['react', 'react-dom', 'react-dom/server'],
|
||||||
},
|
},
|
||||||
ssr: {
|
ssr: {
|
||||||
external: ReactVersion.startsWith('18.')
|
external: isLegacy
|
||||||
? ['react-dom/server', 'react-dom/client']
|
? ['react-dom/server.js', 'react-dom/client.js']
|
||||||
: ['react-dom/server.js', 'react-dom/client.js'],
|
: ['react-dom/server', 'react-dom/client'],
|
||||||
noExternal: [
|
noExternal: [
|
||||||
// These are all needed to get mui to work.
|
// These are all needed to get mui to work.
|
||||||
'@mui/material',
|
'@mui/material',
|
||||||
|
|
Loading…
Reference in a new issue