Skip to content

Commit 61bec49

Browse files
authored
Merge pull request #8060 from QwikDev/v2-fix-repl
v2: refactor JSX handler attributes
2 parents b100ef5 + 61208e1 commit 61bec49

34 files changed

+450
-469
lines changed

.changeset/shaky-pianos-wait.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@qwik.dev/core': major
3+
---
4+
5+
BREAKING: (slightly) `-` handling in JSX event handlers has slightly changed. Now, if an event name starts with `-`, the rest of the name will be kept as-is, preserving casing. Otherwise, the event name is made lowercase. Any `-` characters in the middle of the name are preserved as-is. Previously, `-` were considered to mark the next letter as uppercase.
6+
For example, `onCustomEvent$` will match `customevent`, `on-CustomEvent$` will match `CustomEvent`, and `onCustom-Event$` will match `custom-event`. Before, that last one would match `customEvent` instead.

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"internalConsoleOptions": "neverOpen",
7171
"program": "${workspaceFolder}/./node_modules/vitest/vitest.mjs",
7272
"cwd": "${workspaceFolder}",
73-
"args": ["--test-timeout", "999999", "--minWorkers", "1", "--maxWorkers", "1", "${file}"]
73+
"args": ["--test-timeout", "999999", "--maxWorkers", "1", "${file}"]
7474
}
7575
]
7676
}

e2e/docs-e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "docs-e2e",
33
"description": "",
4-
"private": true,
54
"author": "",
65
"devDependencies": {
76
"@playwright/test": "1.54.1",
@@ -10,6 +9,7 @@
109
"keywords": [],
1110
"license": "ISC",
1211
"main": "index.js",
12+
"private": true,
1313
"scripts": {
1414
"test": "pnpm exec playwright test --config=playwright.config.ts --project=chromium",
1515
"test-ui": "pnpm exec playwright test --config=playwright.config.ts --project=chromium --ui"

e2e/qwik-react-e2e/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "qwik-react-test-app",
33
"description": "Qwik react test app",
4-
"engines": {
5-
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
6-
},
7-
"private": true,
84
"devDependencies": {
95
"@qwik.dev/react": "workspace:*",
106
"@types/react": "19.1.13",
117
"@types/react-dom": "19.1.7",
128
"react": "19.1.1",
139
"react-dom": "19.1.1"
1410
},
11+
"engines": {
12+
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
13+
},
14+
"private": true,
1515
"scripts": {
1616
"build": "qwik build",
1717
"build.client": "vite build",

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@
190190
"build.packages.insights": "pnpm -C ./packages/insights/ run build",
191191
"build.platform": "tsx --require ./scripts/runBefore.ts scripts/index.ts --platform-binding",
192192
"build.platform.copy": "tsx --require ./scripts/runBefore.ts scripts/index.ts --platform-binding-wasm-copy",
193+
"build.qwik-react": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwikreact",
193194
"build.qwik-router": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwikrouter",
194195
"build.router": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwikrouter --api",
195-
"build.qwik-react": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwikreact",
196196
"build.validate": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwik --api --eslint --qwikrouter --platform-binding --wasm --validate",
197197
"build.vite": "tsx --require ./scripts/runBefore.ts scripts/index.ts --tsc --qwik --insights --api --qwikrouter --eslint --platform-binding-wasm-copy",
198198
"build.wasm": "tsx --require ./scripts/runBefore.ts scripts/index.ts --wasm",
@@ -236,11 +236,11 @@
236236
"test.e2e.firefox": "playwright test starters --browser=firefox --config starters/playwright.config.ts",
237237
"test.e2e.integrations.chromium": "playwright test e2e/adapters-e2e/tests --project=chromium --config e2e/adapters-e2e/playwright.config.ts",
238238
"test.e2e.integrations.webkit": "playwright test e2e/adapters-e2e/tests --project=webkit --config e2e/adapters-e2e/playwright.config.ts",
239+
"test.e2e.qwik-react.chromium": "playwright test e2e/qwik-react-e2e/tests --project=chromium --config e2e/qwik-react-e2e/playwright.config.ts",
240+
"test.e2e.qwik-react.webkit": "playwright test e2e/qwik-react-e2e/tests --project=webkit --config e2e/qwik-react-e2e/playwright.config.ts",
239241
"test.e2e.router": "playwright test starters/e2e/qwikrouter --browser=chromium --config starters/playwright.config.ts",
240242
"test.e2e.run": "tsm scripts/e2e-cli.ts",
241243
"test.e2e.webkit": "playwright test starters --browser=webkit --config starters/playwright.config.ts",
242-
"test.e2e.qwik-react.chromium": "playwright test e2e/qwik-react-e2e/tests --project=chromium --config e2e/qwik-react-e2e/playwright.config.ts",
243-
"test.e2e.qwik-react.webkit": "playwright test e2e/qwik-react-e2e/tests --project=webkit --config e2e/qwik-react-e2e/playwright.config.ts",
244244
"test.rust": "make test",
245245
"test.rust.bench": "make benchmark",
246246
"test.rust.update": "make test-update",

packages/docs/src/repl/ui/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ export const Repl = component$((props: ReplProps) => {
9595
if (vNew.version !== input.version) {
9696
input.version = v.version;
9797
}
98-
}
99-
// TODO this is broken, doesn't add the handler on the server
100-
// { strategy: 'document-ready' }
98+
},
99+
{ strategy: 'document-ready' }
101100
);
102101

103102
// Track input changes to rebuild the app

packages/docs/src/routes/api/qwik-router-vite-vercel/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
"mdFile": "router.verceledgeadapteroptions.md"
3232
}
3333
]
34-
}
34+
}

packages/docs/src/routes/docs/(qwik)/core/events/index.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ contributors:
2323
- Balastrong
2424
- Jemsco
2525
- shairez
26-
updated_at: '2024-01-09T20:55:11Z'
26+
- wmertens
27+
updated_at: '2025-10-26T00:00:00Z'
2728
created_at: '2023-03-20T23:45:13Z'
2829
---
2930

@@ -299,6 +300,10 @@ export const Button = component$<ButtonProps>(({ onTripleClick$ }) => {
299300

300301
> Notice the use of the `QRL` type in `onTripleClick$: QRL<() => void>;`. It is like wrapping a function in `$()` but at the type level. If you had `const greet = $(() => "hi 👋");` and hovered over 'greet', you would see that 'greet' is of type `QRL<() => "hi 👋">`
301302
303+
Event names are case sensitive, but all DOM events except for `DOMContentLoaded` are lowercase. For a better DX, event names are always lowercased, so `onTripleClick$` becomes `tripleclick` under the hood.
304+
305+
To listen for a custom event with uppercase letters, you add a `-` after `on`. For example, to listen for a custom event named `CustomEvent`, you would use `on-CustomEvent$`. For a window event named `Hi-There`, you would use `window:on-Hi-There$`.
306+
302307
## Window and Document Events
303308

304309
So far, the discussion has focused on listening to events originating from elements. There are events such as `scroll` and `mousemove` that need to be listened to on the `window` or `document`. Qwik allows this by providing the `document:on` and `window:on` prefixes when listening for events.

packages/docs/src/routes/playground/index!.tsx

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,33 @@ import {
33
$,
44
component$,
55
isBrowser,
6+
useSignal,
67
useStore,
78
useStyles$,
89
useTask$,
910
useVisibleTask$,
1011
} from '@qwik.dev/core';
1112
import type { DocumentHead, RequestHandler } from '@qwik.dev/router';
13+
import type { ReplAppInput } from '~/repl/types';
14+
import { setReplCorsHeaders } from '~/utils/utils';
1215
import { Header } from '../../components/header/header';
1316
import { PanelToggle } from '../../components/panel-toggle/panel-toggle';
14-
import type { ReplAppInput } from '../../repl/types';
1517
import { Repl } from '../../repl/ui';
1618
import { createPlaygroundShareUrl, parsePlaygroundShareUrl } from '../../repl/ui/repl-share-url';
1719
import styles from './playground.css?inline';
18-
import { setReplCorsHeaders } from '~/utils/utils';
1920

2021
export default component$(() => {
2122
useStyles$(styles);
22-
23-
const store = useStore<PlaygroundStore>(() => {
24-
const initStore: PlaygroundStore = {
25-
files: playgroundApp.inputs,
26-
version: '',
27-
buildMode: 'development',
28-
entryStrategy: 'segment',
29-
colResizeActive: false,
30-
colLeft: 50,
31-
shareUrlTmr: null,
32-
};
33-
return initStore;
34-
});
23+
const colResizeActive = useSignal(false);
24+
const colLeft = useSignal(50);
25+
const shareUrlTmr = useSignal<any>(null);
26+
27+
const store = useStore<ReplAppInput>(() => ({
28+
files: playgroundApp.inputs,
29+
version: '',
30+
buildMode: 'development',
31+
entryStrategy: 'segment',
32+
}));
3533

3634
const panelStore = useStore(() => ({
3735
active: 'Input',
@@ -57,9 +55,9 @@ export default component$(() => {
5755

5856
if (isBrowser) {
5957
if (store.version) {
60-
clearTimeout(store.shareUrlTmr);
58+
clearTimeout(shareUrlTmr.value);
6159

62-
store.shareUrlTmr = setTimeout(() => {
60+
shareUrlTmr.value = setTimeout(() => {
6361
const shareUrl = createPlaygroundShareUrl(store);
6462
history.replaceState({}, '', shareUrl);
6563
}, 1000);
@@ -68,19 +66,19 @@ export default component$(() => {
6866
});
6967

7068
const pointerDown = $(() => {
71-
store.colResizeActive = true;
69+
colResizeActive.value = true;
7270
});
7371

7472
const pointerMove = $((ev: PointerEvent) => {
75-
if (store.colResizeActive) {
76-
store.colLeft = (ev.clientX, ev.clientX / window.innerWidth) * 100;
77-
store.colLeft = Math.max(25, store.colLeft);
78-
store.colLeft = Math.min(75, store.colLeft);
73+
if (colResizeActive.value) {
74+
colLeft.value = (ev.clientX / window.innerWidth) * 100;
75+
colLeft.value = Math.max(25, colLeft.value);
76+
colLeft.value = Math.min(75, colLeft.value);
7977
}
8078
});
8179

8280
const pointerUp = $(() => {
83-
store.colResizeActive = false;
81+
colResizeActive.value = false;
8482
});
8583

8684
return (
@@ -89,7 +87,7 @@ export default component$(() => {
8987
playground: true,
9088
'full-width': true,
9189
'fixed-header': true,
92-
'repl-resize-active': store.colResizeActive,
90+
'repl-resize-active': colResizeActive.value,
9391
}}
9492
>
9593
<Header />
@@ -101,7 +99,7 @@ export default component$(() => {
10199
repl: true,
102100
}}
103101
style={{
104-
gridTemplateColumns: `${store.colLeft}% ${100 - store.colLeft}%`,
102+
gridTemplateColumns: `${colLeft.value}% ${100 - colLeft.value}%`,
105103
}}
106104
>
107105
<Repl
@@ -119,7 +117,7 @@ export default component$(() => {
119117
onPointerUp$={pointerUp}
120118
onPointerOut$={pointerUp}
121119
style={{
122-
left: `calc(${store.colLeft}% - 6px)`,
120+
left: `calc(${colLeft.value}% - 6px)`,
123121
}}
124122
/>
125123
<PanelToggle panelStore={panelStore} />
@@ -131,12 +129,6 @@ export const head: DocumentHead = {
131129
title: 'Playground',
132130
};
133131

134-
export interface PlaygroundStore extends ReplAppInput {
135-
colResizeActive: boolean;
136-
colLeft: number;
137-
shareUrlTmr: any;
138-
}
139-
140132
export const onGet: RequestHandler = ({ cacheControl, headers }) => {
141133
cacheControl({
142134
public: true,

packages/qwik/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@
205205
"url": "https://github.com/QwikDev/qwik.git",
206206
"directory": "packages/qwik"
207207
},
208-
"sideEffects": false,
209208
"scripts": {
210209
"build.insights": "cd src/insights && vite build --mode lib --emptyOutDir"
211210
},
211+
"sideEffects": false,
212212
"type": "module",
213213
"types": "./public.d.ts"
214214
}

0 commit comments

Comments
 (0)