Skip to content

fix(lynx): unwrap native event element references in worklet arguments - #395

Merged
trueadm merged 1 commit into
octanejs:mainfrom
Huxpro:fix/lynx-worklet-event-element-refs
Jul 29, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
Huxpro:fix/lynx-worklet-event-element-refs

Conversation

@Huxpro

@Huxpro Huxpro commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Main-thread worklet arguments now unwrap the native event envelope's { elementRefptr } target wrappers to the raw main-thread element instead of rejecting the whole event.

Why

  • On a native engine, Lynx dispatches worklet events whose target/currentTarget are { elementRefptr: <element> } wrappers (the pinned ReactLynx envelope; its worklet runtime converts them to Element instances). Octane's strict data-only argument isolation rejected the wrapper, so every main-thread:bind* handler threw on device: TypeError: Octane Lynx worklet arguments[0].currentTarget.elementRefptr: contains a non-clone-safe value. (Lynx Explorer 3.9, iOS). The JavaScript testing environment never dispatches this envelope, so host tests could not see it.
  • Octane's equivalent of ReactLynx's Element wrapper is the raw PAPI node — the same value a main-thread:ref cell holds — so the unwrap converges both element surfaces.

Changes

  • worklets.ts: CloneState gains an unwrapElementReferences mode used by a new isolateLynxWorkletArguments(); the worklet registry's execute isolates arguments through it. Wrappers unwrap by identity (registered in the clone map so aliases stay aliases); a nullish elementRefptr still fails validation. On PrimJS the element reference's typeof is not necessarily 'object', so only nullish is rejected.
  • Captures, cross-thread calls, and every other isolation boundary keep the strict data-only behavior — the mode exists only for arguments, which never leave the main thread.
  • worklets-core.test.ts: regression asserting the worklet receives the raw element by identity for both target and currentTarget while sibling event data is still isolated by copy.

Validation

  • vitest run --project lynx — 260 tests passed
  • tsgo --noEmit -p packages/lynx/tsconfig.json
  • prettier --check on changed files
  • device evidence: main-thread:bindscroll (Product Gallery scrollbar) and main-thread:bindtouchstart/move/end (Product Detail swiper) execute per-frame on Lynx Explorer 3.9 (iOS) with this change

Risk / follow-ups

  • Worklets can now observe a live element through event.target; that matches the existing main-thread:ref contract and ReactLynx's envelope semantics. No changeset: @octanejs/lynx is private.

Note

Medium Risk
Changes the main-thread worklet argument isolation contract so handlers can observe live native elements via events; scope is limited to args that never leave the main thread.

Overview
Fixes main-thread bind handlers that threw on native Lynx because strict argument cloning rejected the pinned event envelope’s { elementRefptr } wrappers on target / currentTarget.

cloneValue gains an unwrapElementReferences mode (only for worklet args): those wrappers pass through as the raw main-thread element by identity (same as main-thread:ref), with nullish elementRefptr still failing validation. isolateLynxWorkletArguments() uses that mode; the main-thread registry execute path switches from isolateLynxWorkletValue for params. Captures, cross-thread calls, and other isolation boundaries stay data-only.

Adds a regression test: worklet sees native element by identity for both targets while detail remains copy-isolated.

Reviewed by Cursor Bugbot for commit 290774d. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Ready Ready Preview Jul 29, 2026 7:46pm
octane-website-mcp Ready Ready Preview Jul 29, 2026 7:46pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 29, 2026 19:45 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 29, 2026 19:46 Inactive

This branch was previously deployed

2 inactive deployments
Preview – octane-website — 290774dc Deployed Jul 29, 2026 by vercel[bot]
Preview – octane-website-mcp — 290774dc Deployed Jul 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants