-
Notifications
You must be signed in to change notification settings - Fork 19
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
use solid-refresh and solid-devtools babel plugins together? #78
Comments
Looking at the generated code, this is probably a bug on the devtools side. I see some components are annotated: const SidebarMenuItem = _$$component(_REGISTRY, "SidebarMenuItem", function SidebarMenuItem(props: {
}) {
const iconClass = createMemo(() => {
...
}, undefined, {
name: "iconClass"
}); whereas others are not: const SidebarMenu = _$$component(_REGISTRY, "SidebarMenu", function SidebarMenu(props: {
}) {
const showedPinned = createMemo(() => {
...
}); |
Okay confirmed this is a solid-devtools bug. The workaround is: -export function SidebarMenu(
+export { SidebarMenu };
+function SidebarMenu( |
actually, solid-devtools works as-is with both types of components.. the issue is some kind of interaction with solid-refresh if i put the devtools babel plugin first, nothing in the output is annotated. if i put the devtools plugin after solid-refresh, then i get partial annotation which makes sense since devtools isn't setup for the refresh AST? the correct configuration would seem to be devtools first so everything is annotated, then solid-refresh should be able to understand and maintain those annotations? currently it seems to remove them all? |
well i tried a clean build with devtools plugin first and solid-refresh second and everything seems to be working fine. EDIT: scratch that, still had my workaround in place |
as far as I can tell, somehow when |
halluciationRoot cause explanation From the code and transcript, here is what is actually going on:
Hence the second argument with your metadata object goes missing in the final output. The simplest way to think about it is: the plugin does not fully preserve TS type parameters on function calls like createSignal, and in dropping or ignoring type information, the second argument array element winds up lost. In other words, the bug is not in moving or re‑defining the function as a variable. It’s that the type parameter () is confusing (or being stripped by) the refresh code’s AST transforms, which causes the entire extra argument—your annotation object—to get lost when the final output is generated. |
btw how are you setting up the plugins |
one weird thing i discovered is if i left the original component in place, then both copies would be correct. root cause here seems to be related to how babel runs plugins. it does one pass with all of the plugins visitors running once? the simplest fix i found so far is to move the function defintions to the bottom instead of top, which seems to ensure they get processed correctly.
EDIT: tht doesn't work either, just results in |
with patch-package and a patch filediff --git a/node_modules/solid-devtools/dist/babel/named.js b/node_modules/solid-devtools/dist/babel/named.js
new file mode 100644
index 0000000..dc3e20c
--- /dev/null
+++ b/node_modules/solid-devtools/dist/babel/named.js
@@ -0,0 +1,5 @@
+import {
+ namePlugin
+} from "../chunk-RDZMZMK7.js";
+export default function() { return namePlugin };
+
diff --git a/node_modules/solid-devtools/package.json b/node_modules/solid-devtools/package.json
index 6e3d53a..73cda29 100644
--- a/node_modules/solid-devtools/package.json
+++ b/node_modules/solid-devtools/package.json
@@ -78,6 +78,11 @@
"default": "./dist/babel.js"
}
},
+ "./babel/named": {
+ "import": {
+ "default": "./dist/babel/named.js"
+ }
+ },
"./package.json": "./package.json"
},
"typesVersions": { see thetarnav/solid-devtools#295 (comment) i think probably this would work: import { namePlugin } from 'solid-devtools/babel'
...
plugins: [
namePlugin,
["module:solid-refresh/babel"] |
http://thejameskyle.com/babel-plugin-ordering.html basically if we remove the node while solid-devtools plugin is concurrently getting around to processing it, it never gets modified so the moved copy at the top of the file is the original AST. |
this post describes the underlying issue well. both plugins use a i tried to wrangle babel to make this work, but in the end i had to do it manually. --- a/node_modules/solid-refresh/dist/babel.mjs
+++ b/node_modules/solid-refresh/dist/babel.mjs
@@ -1,6 +1,7 @@
import * as t from '@babel/types';
import path from 'path';
import _generator from '@babel/generator';
+import { namePlugin } from 'solid-devtools/babel';
// This is just a Pascal heuristic
// we only assume a function is a component
@@ -1008,6 +1009,9 @@ function solidRefreshPlugin() {
if (setupProgram(state, programPath, context.file.ast.comments)) {
return;
}
+ const devtools = namePlugin.visitor
+ programPath._call(devtools.Program.enter)
+ programPath.traverse(devtools);
programPath.traverse({
FunctionDeclaration(path) {
bubbleFunctionDeclaration(programPath, path); |
that's not exactly reliable, but I can't blame you for that. |
i'm using @solid-devtools/overlay in a project along with solid-refresh
i noticed in the overlay the props/signals/memos are missing names, which can be solved by injecting
solid-devtools/babel
'snamePlugin
into the build pipeline. using this plugin also adds graphs of the reactive relationships between components.https://github.com/thetarnav/solid-devtools/blob/a9c23a428d5639bf138ac2f5793fc57b8eef9136/packages/main/src/babel/babel.ts#L115-L116
however when I use both the devtools and refresh plugin together, the auto names disappear. are these plugins expected to be able to work together?
i tried putting the devtools namePlugin before and after the solid-refresh one.
The text was updated successfully, but these errors were encountered: