mirror of
https://github.com/withastro/astro.git
synced 2025-01-22 10:31:53 -05:00
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>
This commit is contained in:
parent
c30070b927
commit
ea603aec80
5 changed files with 43 additions and 0 deletions
8
.changeset/strong-games-travel.md
Normal file
8
.changeset/strong-games-travel.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
'@astrojs/preact': patch
|
||||
'@astrojs/react': patch
|
||||
'@astrojs/solid-js': patch
|
||||
'@astrojs/vue': patch
|
||||
---
|
||||
|
||||
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.
|
|
@ -71,6 +71,14 @@ export default function ({ include, exclude, compat, devtools }: Options = {}):
|
|||
injectScript('page', 'import "preact/debug";');
|
||||
}
|
||||
},
|
||||
'astro:config:done': ({ logger, config }) => {
|
||||
const knownJsxRenderers = ['@astrojs/react', '@astrojs/preact', '@astrojs/solid-js'];
|
||||
const enabledKnownJsxRenderers = config.integrations.filter((renderer) => knownJsxRenderers.includes(renderer.name));
|
||||
|
||||
if (enabledKnownJsxRenderers.length > 1 && !include && !exclude) {
|
||||
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.');
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -100,6 +100,14 @@ export default function ({
|
|||
injectScript('before-hydration', preamble);
|
||||
}
|
||||
},
|
||||
'astro:config:done': ({ logger, config }) => {
|
||||
const knownJsxRenderers = ['@astrojs/react', '@astrojs/preact', '@astrojs/solid-js'];
|
||||
const enabledKnownJsxRenderers = config.integrations.filter((renderer) => knownJsxRenderers.includes(renderer.name));
|
||||
|
||||
if (enabledKnownJsxRenderers.length > 1 && !include && !exclude) {
|
||||
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.');
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -108,6 +108,14 @@ export default function (options: Options = {}): AstroIntegration {
|
|||
injectScript('page', 'import "solid-devtools";');
|
||||
}
|
||||
},
|
||||
'astro:config:done': ({ logger, config }) => {
|
||||
const knownJsxRenderers = ['@astrojs/react', '@astrojs/preact', '@astrojs/solid-js'];
|
||||
const enabledKnownJsxRenderers = config.integrations.filter((renderer) => knownJsxRenderers.includes(renderer.name));
|
||||
|
||||
if (enabledKnownJsxRenderers.length > 1 && !options.include && !options.exclude) {
|
||||
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.');
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -158,6 +158,17 @@ export default function (options?: Options): AstroIntegration {
|
|||
}
|
||||
updateConfig({ vite: await getViteConfiguration(command, options) });
|
||||
},
|
||||
'astro:config:done': ({ logger, config }) => {
|
||||
if (!options?.jsx) return;
|
||||
|
||||
const knownJsxRenderers = ['@astrojs/react', '@astrojs/preact', '@astrojs/solid-js'];
|
||||
const enabledKnownJsxRenderers = config.integrations.filter((renderer) => knownJsxRenderers.includes(renderer.name));
|
||||
|
||||
// This error can only be thrown from here since Vue is an optional JSX renderer
|
||||
if (enabledKnownJsxRenderers.length > 1 && !options?.include && !options?.exclude) {
|
||||
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.');
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue