Skip to content

Register ChatKit event listeners before applying options - #214

Open
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/subscribe-before-chatkit-configuration
Open

sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/subscribe-before-chatkit-configuration

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Problem

The React wrapper calls setOptions in a layout effect, but registers event listeners in a later passive effect. Synchronous events from initial configuration are missed. On reconfiguration, they can reach the previous handlers instead of the current ones.

Change

Register listeners in a layout effect before applying options. Retain AbortController cleanup and the existing late-definition cancellation path. Add a patch changeset and development-only DOM test dependencies.

Validation

  • 22 tests passed, including six React/DOM lifecycle cases. Three new cases fail on unchanged production code.
  • Coverage includes initial ready/error events, current handlers during reconfiguration, Strict Mode replay, late custom-element definition, unmount before definition, and listener cleanup.
  • CI=1 pnpm check passed formatting, lint, type checks, documentation build, and tests in an isolated temporary checkout. Changed files were byte-checked against the publication checkout.
  • React bindings build passed for ESM, CommonJS, and declaration output. git diff --check passes.

Node 26.8.1, React 19.1.1, Happy DOM 20.14.5 on macOS arm64. Tests use the production wrapper and a synthetic custom element that emits events from setOptions. The hosted ChatKit component and live API were not exercised. Runtime dependencies and public interfaces are unchanged.

Reproduced against 22613848a656077a408788f028c7727e38d10449.

Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

1 participant