Skip to content

Commit

Permalink
fix adding event attribute name for csr
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Feb 1, 2025
1 parent 26564a1 commit 514496b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
48 changes: 29 additions & 19 deletions packages/qwik/src/core/client/vnode-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ export const vnode_diff = (
let vCurrent: VNode | null = null;

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

/// When elements have keys they can be consumed out of order and therefore we can't use nextSibling.
/// In such a case this array will contain the elements after the current location.
Expand Down Expand Up @@ -615,14 +615,25 @@ export const vnode_diff = (
// But we need to mark them so that they don't get pulled into the diff.
const eventName = getEventNameFromJsxProp(key);
const scope = getEventNameScopeFromJsxProp(key);
vnode_setProp(
vNewNode as ElementVNode,
HANDLER_PREFIX + ':' + scope + ':' + eventName,
value
);
if (eventName) {
vnode_setProp(
vNewNode as ElementVNode,
HANDLER_PREFIX + ':' + scope + ':' + eventName,
value
);
registerQwikLoaderEvent(eventName);
}

if (scope) {
// add an event attr with empty value for qwikloader element selector.
// We don't need value here. For ssr this value is a QRL,
// but for CSR value should be just empty
const htmlEvent = convertEventNameFromJsxPropToHtmlAttr(key);
if (htmlEvent) {
vnode_setAttr(journal, vNewNode as ElementVNode, htmlEvent, '');
}
}

needsQDispatchEventPatch = true;
continue;
}
Expand Down Expand Up @@ -831,22 +842,21 @@ export const vnode_diff = (

const recordJsxEvent = (key: string, value: any) => {
const eventName = getEventNameFromJsxProp(key);
const scope = getEventNameScopeFromJsxProp(key);
if (eventName) {
const scope = getEventNameScopeFromJsxProp(key);
record(':' + scope + ':' + eventName, value);
// register an event for qwik loader
registerQwikLoaderEvent(eventName);
}

// add an event attr with empty value for qwikloader element selector.
// We don't need value here. For ssr this value is a QRL,
// but for CSR value should be just empty
const htmlEvent = convertEventNameFromJsxPropToHtmlAttr(key);
if (htmlEvent) {
record(htmlEvent, '');
}

// register an event for qwik loader
if (eventName) {
registerQwikLoaderEvent(eventName);
if (scope) {
// add an event attr with empty value for qwikloader element selector.
// We don't need value here. For ssr this value is a QRL,
// but for CSR value should be just empty
const htmlEvent = convertEventNameFromJsxPropToHtmlAttr(key);
if (htmlEvent) {
record(htmlEvent, '');
}
}
};

Expand Down
6 changes: 6 additions & 0 deletions starters/apps/e2e/src/entry.ssr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export default function (opts: RenderToStreamOptions) {
</head>
<body>
<Root pathname={url.pathname} />
{/* Enable this for debuging qerror events */}
{/* <script
dangerouslySetInnerHTML={
"document.addEventListener('qerror', (e) => console.error(e));"
}
/> */}
</body>
</>,
{
Expand Down
1 change: 1 addition & 0 deletions starters/e2e/e2e.style.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test.describe("styles", () => {
const v = Number(await reload.getAttribute("v"));
await reload.click();
await expect(page.locator("#renderCount")).toHaveText(`Render ${v}`);
await page.waitForSelector("html[q\\:container=resumed]");
});
runTests();
});
Expand Down

0 comments on commit 514496b

Please sign in to comment.