Skip to content

Commit ec8fb19

Browse files
committed
fix open in editor.
1 parent d310c1a commit ec8fb19

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

packages/qwik/src/optimizer/src/plugins/click-to-component.html

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
(function () {
6161
const inspectAttribute = 'data-qwik-inspector';
6262
const hotKeys = globalThis.qwikdevtools.hotKeys;
63-
const srcDir = globalThis.qwikdevtools.srcDir;
63+
const rootDir = globalThis.qwikdevtools.rootDir;
6464
document.querySelector('#qwik-inspector-info-popup').textContent =
6565
`Click-to-Source: ${hotKeys.join(' + ')}`;
6666
console.debug(
@@ -148,20 +148,9 @@
148148
);
149149

150150
globalThis.qwikOpenInEditor = function (path) {
151-
const isWindows = navigator.platform.includes('Win');
152-
const resolvedURL = new URL(path, isWindows ? origin : srcDir);
153-
let filePath =
154-
resolvedURL.protocol === 'file:' && resolvedURL.pathname.startsWith('/')
155-
? resolvedURL.pathname.slice(1)
156-
: resolvedURL.pathname.startsWith('/@fs/')
157-
? resolvedURL.pathname.slice(isWindows ? 5 : 4)
158-
: resolvedURL.pathname;
159-
if (filePath.startsWith('/src/')) {
160-
const prefix = isWindows ? srcDir : srcDir.replace('http://local.local', '');
161-
filePath = prefix + filePath.slice(4);
162-
}
151+
const fullPath = `${rootDir}/${path.replace(/^\//, '')}`;
163152
const params = new URLSearchParams();
164-
params.set('file', filePath);
153+
params.set('file', fullPath);
165154
fetch('/__open-in-editor?' + params.toString());
166155
};
167156
document.addEventListener(

packages/qwik/src/optimizer/src/plugins/vite-dev-server.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ export async function configureDevServer(
269269
});
270270

271271
res.write(
272-
END_SSR_SCRIPT(opts, opts.srcDir ? opts.srcDir : path.join(opts.rootDir, 'src'))
272+
END_SSR_SCRIPT(
273+
opts,
274+
opts.srcDir ? opts.srcDir : path.join(opts.rootDir, 'src'),
275+
opts.rootDir
276+
)
273277
);
274278
res.end();
275279
} else {
@@ -435,10 +439,15 @@ function relativeURL(url: string, base: string) {
435439
return url;
436440
}
437441

438-
const DEV_QWIK_INSPECTOR = (opts: NormalizedQwikPluginOptions['devTools'], srcDir: string) => {
442+
const DEV_QWIK_INSPECTOR = (
443+
opts: NormalizedQwikPluginOptions['devTools'],
444+
srcDir: string,
445+
rootDir: string
446+
) => {
439447
const qwikdevtools = {
440448
hotKeys: opts.clickToSource ?? [],
441449
srcDir: new URL(srcDir + '/', 'http://local.local').href,
450+
rootDir: rootDir,
442451
};
443452
return (
444453
`<script>
@@ -449,12 +458,12 @@ const DEV_QWIK_INSPECTOR = (opts: NormalizedQwikPluginOptions['devTools'], srcDi
449458
);
450459
};
451460

452-
const END_SSR_SCRIPT = (opts: NormalizedQwikPluginOptions, srcDir: string) => `
461+
const END_SSR_SCRIPT = (opts: NormalizedQwikPluginOptions, srcDir: string, rootDir: string) => `
453462
<style>${VITE_ERROR_OVERLAY_STYLES}</style>
454463
<script type="module" src="/@vite/client"></script>
455464
${errorHost}
456465
${perfWarning}
457-
${DEV_QWIK_INSPECTOR(opts.devTools, srcDir)}
466+
${DEV_QWIK_INSPECTOR(opts.devTools, srcDir, rootDir)}
458467
`;
459468

460469
function getViteDevIndexHtml(entryUrl: string, serverData: Record<string, any>) {

0 commit comments

Comments
 (0)