-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: This plugin adds React.createElement even though it's a SolidStart project #60
Comments
Hey @vincehi! Thanks for the issue, unfortunately, I'm afraid I'm not really able to help without further information about your setup. I would at least need to know how you actually set up this plugin within SolidStart's In that example, a entry/barrel file is created in the component folder ( import { defineConfig } from "@solidjs/start/config";
import EntryShakingPlugin from 'vite-plugin-entry-shaking';
import { resolve } from 'node:path';
export default defineConfig({
vite: {
plugins: [
EntryShakingPlugin({
targets: [
resolve(import.meta.dirname, 'src/components'),
],
}),
]
}
}); In that example, you can see that the import { Counter, Link } from '~/components';
export default function App() {
<Counter />
<Link href="https://github.io" />
} Now open the network tab in your browser's devtools:
Hope it helps! If it doesn't, I'd be happy to help further but once again, I would need further information about your setup because well… yeah… React does not have anything to do with this plugin. It's supposed to be 100% framework-agnostic but there might be some kind of conflict with your very specific project. |
Yes, excuse me, import { authVite } from "@solid-mediakit/auth-plugin";
import { defineConfig } from "@solidjs/start/config";
import path, { resolve } from "node:path";
import { fileURLToPath } from "node:url";
import EntryShakingPlugin from "vite-plugin-entry-shaking";
// import Inspect from "vite-plugin-inspect";
import tsconfigPaths from "vite-tsconfig-paths";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default defineConfig({
middleware: "./src/utils/middleware.ts",
vite({ router }) {
return {
ssr: {
external: ["@prisma/client"],
},
plugins: [
EntryShakingPlugin({
targets: [
resolve(__dirname, "src/entry-client.tsx"),
],
maxWildcardDepth: 30,
// diagnostics: true,
// debug: true,
}),
tsconfigPaths({ root: "./" }),
authVite({
authOpts: {
// the variable name of your authOptions (exported!!)
name: "authOptions",
// where your authOptions is located
dir: "@/src/utils/auth",
},
// where should we redirect when the user is not logged in
redirectTo: "/login",
}),
// Inspect(),
],
server: {
port: process.env.APP_CONTAINER_MAIN_PORT,
...(router === "client" && {
hmr: {
port: process.env.APP_CONTAINER_HMR_PORT,
},
}),
},
};
},
}); My tsconfig.json {
"compilerOptions": {
"baseUrl": ".",
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",
"allowJs": true,
"strict": true,
"noEmit": true,
// "sourceMap": true,
"types": [
"vinxi/types/client",
"node"
],
"isolatedModules": true,
"paths": {
"@/*": [
"./*"
]
}
},
"include": [
"src/**/*",
"server/**/*",
"di/**/*",
"styled-system/**/*"
],
"exclude": [
"node_modules",
"styled-system/**/index.d.ts",
"styled-system/**/index.mjs"
]
} I can get it to work on non-JSX packages. |
Hey 👋 Just wanted to let you know that I did not forget about this. I realized my simple repro was irrelevant because I actually never imported anything from the TL;DR(sorry this comment gone pretty dense) I have an incomplete fix that should work if your entry files never actually define code that is later imported (see simple example right below). I'm not sure when I'll be able to find enough free time to further tackle this. Please let me know if you think the partial fix would help/be sufficient for your own scenario , I'm willing to deploy a first patch if this helps :) Given the following config: export default defineConfig({
vite: { plugins: [EntryShakingPlugin({ targets: ["path/to/components"] })] },
}); …and the following entry file: // path/to/components/index.tsx
import Counter from "./Counter";
import Link from "./Link";
const Div = () => <div>Div</div>;
export { Counter, Link, Div }; This would work // consumer.ts (simply rewrites imports to `~/components/Counter.tsx` and `~/components/Link.tsx`)
import { Counter, Link } from "~/components"; But this wouldn't: // consumer.ts (Div is actually defined by `~/components/index.tsx` so it serves its mutated version)
import { Div } from "~/components"; The problems1. files are excluded from transform when they should notThe function used to check whether a file should be transformed or not tries to get the requested module's extension in a very naive way and ignore possible query params (e.g.
(I did set up a branch with a fix about two weeks ago but wanted to also tackle the other problem) 2. esbuild transformsThis plugin recently added JSX support which relies on Vite's I'm still trying to figure out a way of making it work seamlessly but unfortunately I'm not familiar with Solid and its ecosystem. I've made a bunch of tests by manually setting both I've analyzed and compared Vite's outputs both when using and not using this plugin. It seems like Solid's JSX files are actually transformed (maybe by But I think the issue is even more global… Merdouille 😬One of the main pain points of this plugin is that it relies on The more I think about it and about this issue, the more I think that was probably a mistake. From this plugin's perspective, infering the intent of a JSX file (or even the intent of a simple JS module) in any project is quite presomptuous. In the end, depending on (meta-)frameworks toolings, entry files could potentially require pre- or post-transforms. The main question here therefore is: when should this plugin's logic apply? Take any scenario you want, the ideal answer would always end up being "as soon as possible" so that tree-shaking transits down descendants. Such entry files could be processed in any way by (meta-)framwork-specific tooling logic. So we'd rather apply the tree-shaking logic as close as possible from the actual source code to remain as much framework-agnostic as possible. The only thing that's actually preventing us from doing that is In your scenario, Solid is JIT-applying its own transforms to resolved JSX files. Whenever it encounters an entry file that was processed by this plugin, it actually tries to transform the already esbuild-transpiled version instead of the expected raw JSX version. And we've seen above that this esbuild output does not necessarily match what SolidStart expects. Basically, our issue could happen on any other JSX-based framework and a naive fix would highly depend on that framework's tooling implementation around Vite. I only see two possible reliable solutions:
What now?Whenever I've got enough time, I'll investigate using Boshen's
Congrats if you've been brave enough to read this far 😅 In the mean time, and because I'm not sure when I'll be able to tackle this, please refer to the above Tl;DR and let me know if you'd like me to release the "incomplete" patch! |
What does the bug relate to?
Describe the bug
This plugin adds React.createElement even though it's a SolidStart project
To Reproduce
add this plugin on the solidstart project
Vite version
0.5.1
Additional context
No response
The text was updated successfully, but these errors were encountered: