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/fix-event-handler-unique-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/web-core": patch
---

fix: filter out -1 uniqueId in commonEventHandler
29 changes: 29 additions & 0 deletions packages/web-platform/web-core/tests/element-apis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ describe('Element APIs', () => {
true,
);
});
test('#commonEventHandler should filter out -1 uniqueId', () => {
mtsBinding.wasmContext = Object.assign(mtsBinding.wasmContext || {}, {
common_event_handler: vi.fn(),
}) as any;
mtsBinding.addEventListener('touchstart');

const node1 = mtsGlobalThis.__CreateView(0);
const node2 = document.createElement('div') as any;
node1.appendChild(node2);
rootDom.appendChild(node1);

const event = document.createEvent('Event') as any;
event.initEvent('touchstart', true, true);
event.touches = [];
event.targetTouches = [];
event.changedTouches = [];
node2.dispatchEvent(event);

expect(mtsBinding.wasmContext!.common_event_handler).toHaveBeenCalled();
const calls =
(mtsBinding.wasmContext!.common_event_handler as any).mock.calls;
const bubblePath = calls[0][1] as Uint32Array;

// Check that -1 (4294967295 in Uint32Array) is NOT in the bubblePath
for (let i = 0; i < bubblePath.length; i++) {
expect(bubblePath[i] !== 4294967295).toBe(true);
}
});

test('createElementView', () => {
const element = mtsGlobalThis.__CreateElement('view', 0);
expect(mtsGlobalThis.__GetTag(element)).toBe('view');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,13 @@ export class WASMJSBinding implements RustMainthreadContextBinding {
break;
}
const uniqueId = __GetElementUniqueID(currentTarget as HTMLElement);
bubblePath[bubblePathLength++] = uniqueId;
if (bubblePathLength >= bubblePath.length) {
const newBubblePath = new Uint32Array(bubblePath.length * 2);
newBubblePath.set(bubblePath);
bubblePath = newBubblePath;
if (uniqueId !== -1) {
bubblePath[bubblePathLength++] = uniqueId;
if (bubblePathLength >= bubblePath.length) {
const newBubblePath = new Uint32Array(bubblePath.length * 2);
newBubblePath.set(bubblePath);
bubblePath = newBubblePath;
}
}
currentTarget = currentTarget.parentElement as
| DecoratedHTMLElement
Expand Down
Loading