Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-cars-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik': patch
---

fix: Click-to-Component is now more reliable across platforms
4 changes: 2 additions & 2 deletions packages/insights/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@
"test.unit": "vitest",
"test.watch": "vitest --watch"
},
"type": "module",
"sideEffects": false
"sideEffects": false,
"type": "module"
}
4 changes: 2 additions & 2 deletions packages/qwik-city/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
"scripts": {
"build": "cd src/runtime && vite build --mode lib"
},
"sideEffects": false,
"type": "module",
"types": "./lib/index.d.ts",
"sideEffects": false
"types": "./lib/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/qwik-labs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"start": "vite --open --mode ssr",
"test.unit": "vitest"
},
"sideEffects": false,
"type": "module",
"types": "./lib/index.d.ts",
"sideEffects": false
"types": "./lib/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/qwik-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"start": "npm run dev",
"typecheck": "tsc --noEmit"
},
"sideEffects": false,
"type": "module",
"types": "./lib/types/index.qwik.d.ts",
"sideEffects": false
"types": "./lib/types/index.qwik.d.ts"
}
4 changes: 2 additions & 2 deletions packages/qwik-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"scripts": {
"build": "vite build --mode lib"
},
"sideEffects": false,
"type": "module",
"types": "./lib/types/index.d.ts",
"sideEffects": false
"types": "./lib/types/index.d.ts"
}
5 changes: 3 additions & 2 deletions packages/qwik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
],
"dependencies": {
"csstype": "^3.1.3",
"launch-editor": "^2.11.1",
"rollup": ">= ^4.39.0"
},
"devDependencies": {
Expand Down Expand Up @@ -170,7 +171,7 @@
"url": "https://github.com/QwikDev/qwik.git",
"directory": "packages/qwik"
},
"sideEffects": false,
"type": "module",
"types": "./dist/core.d.ts",
"sideEffects": false
"types": "./dist/core.d.ts"
}
26 changes: 8 additions & 18 deletions packages/qwik/src/optimizer/src/plugins/click-to-component.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,34 +136,24 @@
const target = findContainer(event.target);
if (target) {
event.preventDefault();
event.stopPropagation();
const inspectUrl = target.getAttribute(inspectAttribute);
if (inspectUrl !== 'false') {
body.style.setProperty('cursor', 'progress');
qwikOpenInEditor(inspectUrl);
const match = inspectUrl.match(/^(.*?)(:\d+(:\d+)?)?$/);
if (match) {
const [, filePath, location] = match;
fetch(`${filePath}?editor${location}`).then(() => {
body.style.removeProperty('cursor');
});
}
}
}
}
},
{ capture: true }
);

globalThis.qwikOpenInEditor = function (path) {
const isWindows = navigator.platform.includes('Win');
const resolvedURL = new URL(path, isWindows ? origin : srcDir);
let filePath =
resolvedURL.protocol === 'file:' && resolvedURL.pathname.startsWith('/')
? resolvedURL.pathname.slice(1)
: resolvedURL.pathname.startsWith('/@fs/')
? resolvedURL.pathname.slice(isWindows ? 5 : 4)
: resolvedURL.pathname;
if (filePath.startsWith('/src/')) {
const prefix = isWindows ? srcDir : srcDir.replace('http://local.local', '');
filePath = prefix + filePath.slice(4);
}
const params = new URLSearchParams();
params.set('file', filePath);
fetch('/__open-in-editor?' + params.toString());
};
document.addEventListener(
'contextmenu',
(event) => {
Expand Down
51 changes: 43 additions & 8 deletions packages/qwik/src/optimizer/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
/* eslint-disable no-console */
import type { Rollup, Plugin, ViteDevServer, HmrContext } from 'vite';
import type { ManualChunksOption } from 'rollup';
import type { HmrContext, Plugin, Rollup, ViteDevServer } from 'vite';
import type { BundleGraphAdder } from '..';
import { hashCode } from '../../../core/util/hash_code';
import { generateManifestFromBundles, getValidManifest } from '../manifest';
import { createOptimizer } from '../optimizer';
import type {
Diagnostic,
EntryStrategy,
GlobalInjections,
SegmentAnalysis,
Optimizer,
OptimizerOptions,
OptimizerSystem,
QwikManifest,
SegmentAnalysis,
ServerQwikManifest,
SmartEntryStrategy,
TransformModule,
TransformModuleInput,
TransformModulesOptions,
TransformOutput,
SmartEntryStrategy,
ServerQwikManifest,
} from '../types';
import { convertManifestToBundleGraph } from './bundle-graph';
import { createLinter, type QwikLinter } from './eslint-plugin';
import { isWin, parseId } from './vite-utils';
import type { BundleGraphAdder } from '..';
import { convertManifestToBundleGraph } from './bundle-graph';
import type { ManualChunksOption } from 'rollup';

const REG_CTX_NAME = ['server'];

Expand Down Expand Up @@ -427,6 +426,7 @@ export function createQwikPlugin(optimizerOptions: OptimizerOptions = {}) {
};

let resolveIdCount = 0;
let doNotEdit = false;
/**
* This resolves virtual names and QRL segments/entries. All the rest falls through. We must
* always return a value for QRL segments because they don't exist on disk.
Expand All @@ -445,6 +445,35 @@ export function createQwikPlugin(optimizerOptions: OptimizerOptions = {}) {
if (id.startsWith('\0')) {
return;
}

// Intercept requests to open in editor
const editMatch = devServer && /^(.*)\?editor(:(\d+)(:\d+)?)?$/.exec(id);
if (editMatch) {
// Throttle so we don't open multiple times on re-resolve
if (!doNotEdit) {
doNotEdit = true;
setTimeout(() => (doNotEdit = false), 500);

const [, origId, location] = editMatch;
// Find the actual file on disk by asking vite to resolve it
const resolved = await ctx.resolve(origId, importerId);
if (resolved) {
const file = devServer!.moduleGraph.getModuleById(resolved.id)?.file;
if (file) {
const path = `${file}${location}`;
try {
console.warn(`Opening in editor: ${path}`);
const launchEditor = (await import('launch-editor')).default;
launchEditor(path);
} catch (e: any) {
console.error(`Failed to open editor: ${e.message}`);
}
}
}
}
return { id: `\0editor` };
}

const count = resolveIdCount++;
const isServer = getIsServer(resolveOpts);
debug(`resolveId(${count})`, `begin ${id} | ${isServer ? 'server' : 'client'} | ${importerId}`);
Expand Down Expand Up @@ -577,6 +606,10 @@ export function createQwikPlugin(optimizerOptions: OptimizerOptions = {}) {
id: string,
loadOpts?: Parameters<Extract<Plugin['load'], Function>>[1]
): Promise<Rollup.LoadResult> => {
if (id === '\0editor') {
// This doesn't get used, but we need to return something
return '"opening in editor"';
}
if (id.startsWith('\0') || id.startsWith('/@fs/')) {
return;
}
Expand Down Expand Up @@ -850,11 +883,13 @@ export function createQwikPlugin(optimizerOptions: OptimizerOptions = {}) {

const debug = (...str: any[]) => {
if (opts.debug) {
// eslint-disable-next-line no-console
console.debug(`[QWIK PLUGIN: ${id}]`, ...str);
}
};

const log = (...str: any[]) => {
// eslint-disable-next-line no-console
console.log(`[QWIK PLUGIN: ${id}]`, ...str);
};

Expand Down
3 changes: 3 additions & 0 deletions packages/qwik/src/optimizer/src/plugins/vite-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ const shouldSsrRender = (req: IncomingMessage, url: URL) => {
if (pathname.includes('__open-in-editor')) {
return false;
}
if (pathname.includes('?editor:')) {
return false;
}
if (url.searchParams.has('html-proxy')) {
return false;
}
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
packages:
- 'packages/*'
- 'e2e/*'
# - 'starters/adapter/*'
# - 'starters/features/*'
- packages/*
- e2e/*

autoInstallPeers: false

engineStrict: true

onlyBuiltDependencies:
- '@parcel/watcher'
- '@tailwindcss/oxide'
- 'esbuild'
- 'netlify-cli'
- 'puppeteer'
- 'sharp'
- 'simple-git-hooks'
- 'unix-dgram'
- 'workerd'
- esbuild
- netlify-cli
- puppeteer
- sharp
- simple-git-hooks
- unix-dgram
- workerd

overrides:
'typescript': '5.4.5'
'vfile': '6.0.3'
typescript: 5.4.5
vfile: 6.0.3

patchedDependencies:
'density-clustering@1.3.0': 'patches/density-clustering@1.3.0.patch'
'domino@2.1.6': 'patches/domino@2.1.6.patch'
density-clustering@1.3.0: patches/density-clustering@1.3.0.patch
domino@2.1.6: patches/domino@2.1.6.patch

engineStrict: true
shellEmulator: true
autoInstallPeers: false
1 change: 1 addition & 0 deletions scripts/submodule-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function submoduleOptimizer(config: BuildConfig) {
external: [
/* no Node.js built-in externals allowed! */
'espree',
'launch-editor',
],
};

Expand Down
Loading