Skip to content

Commit ea603ae

Browse files
louisescherflorian-lefebvrebluwy
authoredJan 14, 2025··
Add warnings if multiple JSX renderers are used (#12887)
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
1 parent c30070b commit ea603ae

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed
 

‎.changeset/strong-games-travel.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@astrojs/preact': patch
3+
'@astrojs/react': patch
4+
'@astrojs/solid-js': patch
5+
'@astrojs/vue': patch
6+
---
7+
8+
Adds a warning message when multiple JSX-based UI frameworks are being used without either the `include` or `exclude` property being set on the integration.

‎packages/integrations/preact/src/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ export default function ({ include, exclude, compat, devtools }: Options = {}):
7171
injectScript('page', 'import "preact/debug";');
7272
}
7373
},
74+
'astro:config:done': ({ logger, config }) => {
75+
const knownJsxRenderers = ['@astrojs/react', '@astrojs/preact', '@astrojs/solid-js'];
76+
const enabledKnownJsxRenderers = config.integrations.filter((renderer) => knownJsxRenderers.includes(renderer.name));
77+
78+
if (enabledKnownJsxRenderers.length > 1 && !include && !exclude) {
79+
logger.warn('More than one JSX renderer is enabled. This will lead to unexpected behavior unless you set the `include` or `exclude` option. See https://docs.astro.build/en/guides/integrations-guide/preact/#combining-multiple-jsx-frameworks for more information.');
80+
}
81+
}
7482
},
7583
};
7684
}

‎packages/integrations/react/src/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ export default function ({
100100
injectScript('before-hydration', preamble);
101101
}
102102
},
103+
'astro:config:done': ({ logger, config }) => {
104+
const knownJsxRenderers = ['@astrojs/react', '@astrojs/preact', '@astrojs/solid-js'];
105+
const enabledKnownJsxRenderers = config.integrations.filter((renderer) => knownJsxRenderers.includes(renderer.name));
106+
107+
if (enabledKnownJsxRenderers.length > 1 && !include && !exclude) {
108+
logger.warn('More than one JSX renderer is enabled. This will lead to unexpected behavior unless you set the `include` or `exclude` option. See https://docs.astro.build/en/guides/integrations-guide/react/#combining-multiple-jsx-frameworks for more information.');
109+
}
110+
}
103111
},
104112
};
105113
}

‎packages/integrations/solid/src/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ export default function (options: Options = {}): AstroIntegration {
108108
injectScript('page', 'import "solid-devtools";');
109109
}
110110
},
111+
'astro:config:done': ({ logger, config }) => {
112+
const knownJsxRenderers = ['@astrojs/react', '@astrojs/preact', '@astrojs/solid-js'];
113+
const enabledKnownJsxRenderers = config.integrations.filter((renderer) => knownJsxRenderers.includes(renderer.name));
114+
115+
if (enabledKnownJsxRenderers.length > 1 && !options.include && !options.exclude) {
116+
logger.warn('More than one JSX renderer is enabled. This will lead to unexpected behavior unless you set the `include` or `exclude` option. See https://docs.astro.build/en/guides/integrations-guide/solid-js/#combining-multiple-jsx-frameworks for more information.');
117+
}
118+
}
111119
},
112120
};
113121
}

‎packages/integrations/vue/src/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ export default function (options?: Options): AstroIntegration {
158158
}
159159
updateConfig({ vite: await getViteConfiguration(command, options) });
160160
},
161+
'astro:config:done': ({ logger, config }) => {
162+
if (!options?.jsx) return;
163+
164+
const knownJsxRenderers = ['@astrojs/react', '@astrojs/preact', '@astrojs/solid-js'];
165+
const enabledKnownJsxRenderers = config.integrations.filter((renderer) => knownJsxRenderers.includes(renderer.name));
166+
167+
// This error can only be thrown from here since Vue is an optional JSX renderer
168+
if (enabledKnownJsxRenderers.length > 1 && !options?.include && !options?.exclude) {
169+
logger.warn('More than one JSX renderer is enabled. This will lead to unexpected behavior unless you set the `include` or `exclude` option. See https://docs.astro.build/en/guides/integrations-guide/solid-js/#combining-multiple-jsx-frameworks for more information.');
170+
}
171+
}
161172
},
162173
};
163174
}

0 commit comments

Comments
 (0)
Please sign in to comment.