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/clone-touch-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/web-core": patch
---

Always clone touch event lists when creating cross-thread events so synthetic touch events only carry structured-clone-safe primitive fields.
19 changes: 19 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 @@ -135,6 +135,25 @@ describe('Element APIs', () => {
expect(lynxEvent.detail).toEqual({ x: 100, y: 200 });
});

test('createCrossThreadEvent clone touches for untrusted events', async () => {
const { createCrossThreadEvent } = await import(
'../ts/client/mainthread/elementAPIs/createCrossThreadEvent.js'
);
const touchEvent = new Event('touchstart') as any;
touchEvent.touches = [{
clientX: 100,
clientY: 200,
nested: { ignored: true },
}];
touchEvent.targetTouches = [{ identifier: 1, target: {} }];
touchEvent.changedTouches = [{ pageX: 10, preventDefault: () => {} }];

const lynxEvent = createCrossThreadEvent(touchEvent);
expect(lynxEvent.touches).toEqual([{ clientX: 100, clientY: 200 }]);
expect(lynxEvent.targetTouches).toEqual([{ identifier: 1 }]);
expect(lynxEvent.changedTouches).toEqual([{ pageX: 10 }]);
});

test('createCrossThreadEvent sets empty detail if no touches', async () => {
const { createCrossThreadEvent } = await import(
'../ts/client/mainthread/elementAPIs/createCrossThreadEvent.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function createCrossThreadEvent(
): LynxCrossThreadEvent {
const type = domEvent.type;
const params: Cloneable = {};
const isTrusted = domEvent.isTrusted;
const otherProperties: CloneableObject = {};
let detail = domEvent.detail ?? {};
if (type.match(/^transition/)) {
Expand All @@ -49,17 +48,9 @@ export function createCrossThreadEvent(
const targetTouches = [...touchEvent.targetTouches as unknown as Touch[]];
const changedTouches = [...touchEvent.changedTouches as unknown as Touch[]];
Object.assign(otherProperties, {
touches: isTrusted ? touch.map(toCloneableObject) : touch,
targetTouches: isTrusted
? targetTouches.map(
toCloneableObject,
)
: targetTouches,
changedTouches: isTrusted
? changedTouches.map(
toCloneableObject,
)
: changedTouches,
touches: touch.map(toCloneableObject),
targetTouches: targetTouches.map(toCloneableObject),
changedTouches: changedTouches.map(toCloneableObject),
});
if (touch[0]) {
detail = {
Expand Down
Loading