Skip to content

Commit 040a5e8

Browse files
authored
fix: error while as a plugin (#48)
1 parent ab8a429 commit 040a5e8

File tree

11 files changed

+83
-158
lines changed

11 files changed

+83
-158
lines changed

packages/devtools/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"qwik": "./dist/ui/index.qwik.mjs",
88
"exports": {
99
".": {
10-
"import": "./dist/plugin/index.mjs",
10+
"import": "./dist/plugin/index.js",
1111
"types": "./dist/plugin/index.d.ts"
1212
},
1313
"./ui": {
@@ -22,8 +22,8 @@
2222
],
2323
"peerDependencies": {
2424
"vite": "7.1.3",
25-
"@qwik.dev/core": "2.0.0-beta.8",
26-
"@qwik.dev/router": "2.0.0-beta.8"
25+
"@qwik.dev/core": "2.0.0-beta.9",
26+
"@qwik.dev/router": "2.0.0-beta.9"
2727
},
2828
"dependencies": {
2929
"birpc": "^0.2.19",
@@ -32,7 +32,9 @@
3232
"@qwikest/icons": "^0.0.13",
3333
"vite-hot-client": "^0.2.4"
3434
},
35+
"type": "module",
3536
"devDependencies": {
37+
"oxc-parser": "^0.82.1",
3638
"tsx": "^4.19.2",
3739
"@types/node": "^22.10.5",
3840
"@changesets/cli": "^2.27.11",

packages/kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@typescript-eslint/parser": "7.16.1",
3333
"cpy-cli": "^5.0.0",
3434
"eslint": "8.57.0",
35-
"eslint-plugin-qwik": "2.0.0-beta.8",
35+
"eslint-plugin-qwik": "2.0.0-beta.9",
3636
"np": "^8.0.4",
3737
"prettier": "3.3.3",
3838
"typescript": "5.4.5",

packages/playgrounds/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
"devDependencies": {
3030
"@devtools/plugin": "workspace:*",
3131
"@devtools/ui": "workspace:*",
32-
"@qwik.dev/core": "2.0.0-beta.8",
33-
"@qwik.dev/router": "2.0.0-beta.8",
32+
"@qwik.dev/core": "2.0.0-beta.9",
33+
"@qwik.dev/router": "2.0.0-beta.9",
3434
"@types/eslint": "8.56.10",
3535
"@types/node": "20.14.11",
3636
"@typescript-eslint/eslint-plugin": "7.16.1",
3737
"@typescript-eslint/parser": "7.16.1",
3838
"eslint": "8.57.0",
39-
"eslint-plugin-qwik": "2.0.0-beta.8",
39+
"eslint-plugin-qwik": "2.0.0-beta.9",
4040
"prettier": "3.3.3",
4141
"typescript": "5.4.5",
4242
"vite": "7.1.3",

packages/plugin/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"devDependencies": {
2626
"@babel/types": "^7.26.7",
2727
"@devtools/kit": "workspace:*",
28+
"@qwik.dev/core": "2.0.0-beta.9",
2829
"@types/eslint": "8.56.10",
2930
"@types/node": "20.14.11",
3031
"@typescript-eslint/eslint-plugin": "7.16.1",

packages/plugin/src/index.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { ResolvedConfig, type Plugin } from 'vite';
22
import { getServerFunctions } from './rpc';
33
import { createServerRpc, setViteServerContext, VIRTUAL_QWIK_DEVTOOLS_KEY, INNER_USE_HOOK } from '@devtools/kit';
4-
import _traverse from '@babel/traverse';
5-
import _generate from '@babel/generator';
64
import VueInspector from 'vite-plugin-inspect'
75
import useCollectHooksSource from './utils/useCollectHooks'
86
import { parseQwikCode } from './parse/parse';
@@ -15,13 +13,28 @@ export function qwikDevtools(): Plugin[] {
1513
name: 'vite-plugin-qwik-devtools',
1614
apply: 'serve',
1715
resolveId(id) {
18-
if (id === VIRTUAL_QWIK_DEVTOOLS_KEY) {
19-
return id;
16+
// Normalize to a stable, absolute-like id so Qwik can generate runtime chunks
17+
const clean = id.split('?')[0].split('#')[0];
18+
if (
19+
clean === VIRTUAL_QWIK_DEVTOOLS_KEY ||
20+
clean === `/${VIRTUAL_QWIK_DEVTOOLS_KEY}` ||
21+
clean === `\u0000${VIRTUAL_QWIK_DEVTOOLS_KEY}` ||
22+
clean === `/@id/${VIRTUAL_QWIK_DEVTOOLS_KEY}`
23+
) {
24+
return `/${VIRTUAL_QWIK_DEVTOOLS_KEY}`;
2025
}
2126
},
2227
load(id) {
23-
if (id === VIRTUAL_QWIK_DEVTOOLS_KEY) {
24-
return useCollectHooksSource;
28+
if (
29+
id === `/${VIRTUAL_QWIK_DEVTOOLS_KEY}` ||
30+
id === VIRTUAL_QWIK_DEVTOOLS_KEY ||
31+
id === `\u0000${VIRTUAL_QWIK_DEVTOOLS_KEY}` ||
32+
id === `/@id/${VIRTUAL_QWIK_DEVTOOLS_KEY}`
33+
) {
34+
return {
35+
code: useCollectHooksSource,
36+
map: null,
37+
};
2538
}
2639
},
2740
configResolved(viteConfig) {
@@ -49,14 +62,11 @@ export function qwikDevtools(): Plugin[] {
4962
code = `import { QwikDevtools } from '${importPath}';\n${code}`;
5063
}
5164

52-
// Find the closing body tag and inject the QwikDevtools component before it
65+
// Find the closing body tag and append QwikDevtools at the end of body
5366
const match = code.match(/<body[^>]*>([\s\S]*?)<\/body>/);
5467
if (match) {
5568
const bodyContent = match[1];
56-
const newBodyContent = bodyContent.replace(
57-
/{!isDev && <ServiceWorkerRegister \/>}/,
58-
`{!isDev && <ServiceWorkerRegister />}\n {isDev && <QwikDevtools />}`,
59-
);
69+
const newBodyContent = `${bodyContent}\n <QwikDevtools />`;
6070
code = code.replace(bodyContent, newBodyContent);
6171
}
6272

packages/plugin/src/utils/useCollectHooks.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ export const useCollectHooks = (src) => {
33
const hooksList = useSignal([])
44
useVisibleTask$(({ track }) => {
55
const newdata = track(() => hooksList.value);
6-
76
if(!window.QWIK_DEVTOOLS_GLOBAL_STATE) {
87
window.QWIK_DEVTOOLS_GLOBAL_STATE = {}
9-
window.QWIK_DEVTOOLS_GLOBAL_STATE[src] = []
8+
window.QWIK_DEVTOOLS_GLOBAL_STATE[src] = newdata || []
109
}else {
1110
window.QWIK_DEVTOOLS_GLOBAL_STATE[src] = newdata
1211
}

packages/plugin/tsdown.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { defineConfig } from 'tsdown'
33
export default defineConfig({
44
entry: ['src/index.ts'],
55
clean: true,
6+
target: 'esnext',
67
format: ['esm'],
7-
external: ['vite','vite-plugin-inspect'],
8+
external: ['vite','vite-plugin-inspect', '@qwik.dev/core'],
89
dts: true,
910
shims: true,
1011
tsconfig: './tsconfig.json',

packages/ui/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
},
3636
"peerDependencies": {
3737
"@devtools/plugin": "workspace:*",
38-
"@qwik.dev/core": "2.0.0-beta.8"
38+
"@qwik.dev/core": "2.0.0-beta.9"
3939
},
4040
"devDependencies": {
4141
"@devtools/kit": "workspace:*",
42-
"@qwik.dev/react": "2.0.0-beta.8",
42+
"@qwik.dev/react": "2.0.0-beta.9",
4343
"@qwikest/icons": "^0.0.13",
4444
"@types/eslint": "8.56.10",
4545
"@types/node": "20.14.11",

packages/ui/src/features/RenderTree/data.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ export const getQwikState = (qrl: string) => {
2222
const stateKeyPath = Object.keys(window.QWIK_DEVTOOLS_GLOBAL_STATE)?.find(
2323
(key) => key.endsWith(qrl!),
2424
);
25-
//@ts-ignore
25+
2626
return (
2727
(
28+
//@ts-ignore
2829
window.QWIK_DEVTOOLS_GLOBAL_STATE?.[stateKeyPath] as ParsedStructure[]
2930
)?.filter((item) => !!item.data) || []
3031
);

packages/ui/vite.config.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export default defineConfig(() => {
3838
external: [
3939
'stream',
4040
'util',
41+
'@qwik.dev/core',
42+
'@qwik.dev/router',
4143
/^node:.*/,
4244
...excludeAll(peerDependencies),
4345
...excludeAll(dependencies),

0 commit comments

Comments
 (0)