Skip to content

addEventListener('message') conflicts with wasm-bindgen's internal handler #24

@jiangheng90

Description

@jiangheng90

Steps to reproduce

  1. Use #[webworker_fn] or #[webworker_channel_fn] with a worker pool
  2. The worker has addEventListener('message', handler) for task dispatch
  3. Send several tasks to the pool

Expected

Only the addEventListener handler processes messages.

Actual

Both addEventListener and wasm-bindgen's internally registered handler fire.
The wasm-bindgen handler receives wasmworker's {id, func_name, is_channel, arg}
format and fails:

TypeError: Cannot read properties of undefined (reading 'length')
Could not deserialize response

Root cause

mod.default() during init registers a message handler (via self.onmessage
setter). Subsequent addEventListener('message', ...) adds a second handler,
and both fire for every postMessage.

Proposed fix

Lock onmessage via Object.defineProperty with a no-op setter after
mod.default(), so addEventListener remains the sole dispatch path.

See commit: 200ec0e
PR: #25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions