Skip to content

Commit 5b1b240

Browse files
committed
fix adding event attribute name for csr
1 parent 26564a1 commit 5b1b240

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

Diff for: packages/qwik/src/core/client/vnode-diff.ts

+29-19
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ export const vnode_diff = (
137137
let vCurrent: VNode | null = null;
138138

139139
/// When we insert new node we start it here so that we can descend into it.
140-
/// NOTE: it can't be stored in `vCurrent` because `vNewCurrent` is in journal
140+
/// NOTE: it can't be stored in `vCurrent` because `vNewNode` is in journal
141141
/// and is not connected to the tree.
142-
let vNewNode: VNode | null = null; // TODO: delete, because journal is on vNode, the above comment no longer applies
142+
let vNewNode: VNode | null = null;
143143

144144
/// When elements have keys they can be consumed out of order and therefore we can't use nextSibling.
145145
/// In such a case this array will contain the elements after the current location.
@@ -615,14 +615,25 @@ export const vnode_diff = (
615615
// But we need to mark them so that they don't get pulled into the diff.
616616
const eventName = getEventNameFromJsxProp(key);
617617
const scope = getEventNameScopeFromJsxProp(key);
618-
vnode_setProp(
619-
vNewNode as ElementVNode,
620-
HANDLER_PREFIX + ':' + scope + ':' + eventName,
621-
value
622-
);
623618
if (eventName) {
619+
vnode_setProp(
620+
vNewNode as ElementVNode,
621+
HANDLER_PREFIX + ':' + scope + ':' + eventName,
622+
value
623+
);
624624
registerQwikLoaderEvent(eventName);
625625
}
626+
627+
if (scope) {
628+
// add an event attr with empty value for qwikloader element selector.
629+
// We don't need value here. For ssr this value is a QRL,
630+
// but for CSR value should be just empty
631+
const htmlEvent = convertEventNameFromJsxPropToHtmlAttr(key);
632+
if (htmlEvent) {
633+
vnode_setAttr(journal, vNewNode as ElementVNode, htmlEvent, '');
634+
}
635+
}
636+
626637
needsQDispatchEventPatch = true;
627638
continue;
628639
}
@@ -831,22 +842,21 @@ export const vnode_diff = (
831842

832843
const recordJsxEvent = (key: string, value: any) => {
833844
const eventName = getEventNameFromJsxProp(key);
845+
const scope = getEventNameScopeFromJsxProp(key);
834846
if (eventName) {
835-
const scope = getEventNameScopeFromJsxProp(key);
836847
record(':' + scope + ':' + eventName, value);
848+
// register an event for qwik loader
849+
registerQwikLoaderEvent(eventName);
837850
}
838851

839-
// add an event attr with empty value for qwikloader element selector.
840-
// We don't need value here. For ssr this value is a QRL,
841-
// but for CSR value should be just empty
842-
const htmlEvent = convertEventNameFromJsxPropToHtmlAttr(key);
843-
if (htmlEvent) {
844-
record(htmlEvent, '');
845-
}
846-
847-
// register an event for qwik loader
848-
if (eventName) {
849-
registerQwikLoaderEvent(eventName);
852+
if (scope) {
853+
// add an event attr with empty value for qwikloader element selector.
854+
// We don't need value here. For ssr this value is a QRL,
855+
// but for CSR value should be just empty
856+
const htmlEvent = convertEventNameFromJsxPropToHtmlAttr(key);
857+
if (htmlEvent) {
858+
record(htmlEvent, '');
859+
}
850860
}
851861
};
852862

Diff for: starters/apps/e2e/src/entry.ssr.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export default function (opts: RenderToStreamOptions) {
1717
return renderToStream(
1818
<>
1919
<Root pathname={url.pathname} />
20+
<script
21+
dangerouslySetInnerHTML={
22+
"document.addEventListener('qerror', (e) => console.error(e));"
23+
}
24+
/>
2025
</>,
2126
{
2227
debug: true,
@@ -43,6 +48,11 @@ export default function (opts: RenderToStreamOptions) {
4348
</head>
4449
<body>
4550
<Root pathname={url.pathname} />
51+
<script
52+
dangerouslySetInnerHTML={
53+
"document.addEventListener('qerror', (e) => console.error(e));"
54+
}
55+
/>
4656
</body>
4757
</>,
4858
{

0 commit comments

Comments
 (0)