Skip to content

Commit ed57e4d

Browse files
authored
Merge pull request #7419 from QwikDev/v2-var-attribute-diff
fix: attribute diffing
2 parents e7433d2 + 008fe60 commit ed57e4d

File tree

12 files changed

+622
-117
lines changed

12 files changed

+622
-117
lines changed

.changeset/friendly-beers-heal.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik.dev/core': patch
3+
---
4+
5+
fix: attribute diffing was not working correctly in some edge cases

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ test-results
5252
sandbox
5353

5454
# We need to ignore this because "changesets" will try to replace it
55-
/CHANGELOG.md
55+
/CHANGELOG.md
56+
57+
# Vitest coverage
58+
packages/coverage/*

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
"@types/which-pm-runs": "1.0.2",
116116
"@typescript-eslint/eslint-plugin": "7.16.1",
117117
"@typescript-eslint/parser": "7.16.1",
118+
"@vitest/coverage-v8": "3.0.8",
118119
"all-contributors-cli": "6.26.1",
119120
"brotli": "1.3.3",
120121
"concurrently": "8.2.2",
@@ -155,7 +156,7 @@
155156
"vite-imagetools": "7.0.4",
156157
"vite-plugin-dts": "4.3.0",
157158
"vite-tsconfig-paths": "5.0.1",
158-
"vitest": "2.1.4",
159+
"vitest": "3.0.8",
159160
"watchlist": "0.3.1",
160161
"which-pm-runs": "1.1.0",
161162
"zod": "3.22.4"

packages/insights/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"undici": "*",
3636
"vite": "5.4.10",
3737
"vite-tsconfig-paths": "5.0.1",
38-
"vitest": "2.1.4",
38+
"vitest": "3.0.8",
3939
"zod": "3.22.4"
4040
},
4141
"engines": {

packages/qwik/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"kleur": "4.1.5",
1919
"prettier": "3.4.2",
2020
"ts-morph": "23.0.0",
21-
"vitest": "2.1.4"
21+
"vitest": "3.0.8"
2222
},
2323
"engines": {
2424
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"

packages/qwik/src/core/client/vnode-diff.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,9 @@ export const vnode_diff = (
832832
} else if (typeof value === 'function') {
833833
value(element);
834834
return;
835-
} else if (value == null) {
836-
return;
837-
} else {
835+
}
836+
// handling null value is not needed here, because we are filtering null values earlier
837+
else {
838838
throw qError(QError.invalidRefValue, [currentFile]);
839839
}
840840
}
@@ -847,7 +847,12 @@ export const vnode_diff = (
847847
value = trackSignalAndAssignHost(value, vnode, key, container, signalData);
848848
}
849849

850-
vnode_setAttr(journal, vnode, key, serializeAttribute(key, value, scopedStyleIdPrefix));
850+
vnode_setAttr(
851+
journal,
852+
vnode,
853+
key,
854+
value !== null ? serializeAttribute(key, value, scopedStyleIdPrefix) : null
855+
);
851856
if (value === null) {
852857
// if we set `null` than attribute was removed and we need to shorten the dstLength
853858
dstLength = dstAttrs.length;
@@ -883,7 +888,6 @@ export const vnode_diff = (
883888
} else if (srcKey == null) {
884889
// Source has more keys, so we need to remove them from destination
885890
if (dstKey && isHtmlAttributeAnEventName(dstKey)) {
886-
patchEventDispatch = true;
887891
dstIdx++;
888892
} else {
889893
record(dstKey!, null);
@@ -930,6 +934,7 @@ export const vnode_diff = (
930934
// we need to increment dstIdx too, because we added destination key and value to the VNode
931935
// and dstAttrs is a reference to the VNode
932936
dstIdx++;
937+
dstLength = dstAttrs.length;
933938
dstKey = dstIdx < dstLength ? dstAttrs[dstIdx++] : null;
934939
} else {
935940
// Source is missing the key, so we need to remove it from destination.
@@ -1444,7 +1449,7 @@ function markVNodeAsDeleted(vCursor: VNode) {
14441449
* This marks the property as immutable. It is needed for the QRLs so that QwikLoader can get a hold
14451450
* of them. This character must be `:` so that the `vnode_getAttr` can ignore them.
14461451
*/
1447-
const HANDLER_PREFIX = ':';
1452+
export const HANDLER_PREFIX = ':';
14481453
let count = 0;
14491454
const enum SiblingsArray {
14501455
Name = 0,

0 commit comments

Comments
 (0)