summaryrefslogtreecommitdiff
path: root/packages/integrations/react/src
diff options
context:
space:
mode:
authorGravatar Emanuele Stoppa <my.burning@gmail.com> 2024-06-05 11:39:42 +0100
committerGravatar GitHub <noreply@github.com> 2024-06-05 11:39:42 +0100
commit803dd8061df02138b4928442bcb76e77dcf6f5e7 (patch)
treec3ed3580e82716ea436dc783fdb31dd8bbc9f647 /packages/integrations/react/src
parent587e75f47efa346139b71e5e754e051f72bdac39 (diff)
downloadastro-803dd8061df02138b4928442bcb76e77dcf6f5e7.tar.gz
astro-803dd8061df02138b4928442bcb76e77dcf6f5e7.tar.zst
astro-803dd8061df02138b4928442bcb76e77dcf6f5e7.zip
feat(container): provide a virtual module to load renderers (#11144)
* feat(container): provide a virtual module to load renderers * address feedback * chore: restore some default to allow to have PHP prototype working * Thread through renderers and manifest * Pass manifest too * update changeset * add diff * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * fix diff * rebase and update lock --------- Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Diffstat (limited to 'packages/integrations/react/src')
-rw-r--r--packages/integrations/react/src/index.ts15
1 files changed, 14 insertions, 1 deletions
diff --git a/packages/integrations/react/src/index.ts b/packages/integrations/react/src/index.ts
index 838640239..85d79eef8 100644
--- a/packages/integrations/react/src/index.ts
+++ b/packages/integrations/react/src/index.ts
@@ -1,5 +1,5 @@
import react, { type Options as ViteReactPluginOptions } from '@vitejs/plugin-react';
-import type { AstroIntegration } from 'astro';
+import type { AstroIntegration, ContainerRenderer } from 'astro';
import { version as ReactVersion } from 'react-dom';
import type * as vite from 'vite';
@@ -53,6 +53,19 @@ function getRenderer(reactConfig: ReactVersionConfig) {
};
}
+export function getContainerRenderer(): ContainerRenderer {
+ const majorVersion = getReactMajorVersion();
+ if (isUnsupportedVersion(majorVersion)) {
+ throw new Error(`Unsupported React version: ${majorVersion}.`);
+ }
+ const versionConfig = versionsConfig[majorVersion as SupportedReactVersion];
+
+ return {
+ name: '@astrojs/react',
+ serverEntrypoint: versionConfig.server,
+ };
+}
+
function optionsPlugin(experimentalReactChildren: boolean): vite.Plugin {
const virtualModule = 'astro:react:opts';
const virtualModuleId = '\0' + virtualModule;