Skip to content

[Backport of #278] fix(data-consumption): unsubscribe with current args on unmount & test: initial unit test setup#279

Open
Arthurk12 wants to merge 3 commits into
bigbluebutton:v0.0.xfrom
Arthurk12:plugins-sdk/v0.0.x/issue/275
Open

[Backport of #278] fix(data-consumption): unsubscribe with current args on unmount & test: initial unit test setup#279
Arthurk12 wants to merge 3 commits into
bigbluebutton:v0.0.xfrom
Arthurk12:plugins-sdk/v0.0.x/issue/275

Conversation

@Arthurk12

Copy link
Copy Markdown
Member

What does this PR do?

  • createDataConsumptionHook kept its unmount cleanup in a mount-only effect, closing over the first render's query/variables. After a custom subscription changed variables, unmount dispatched PLUGIN_UNSUBSCRIBED_FROM_BBB_CORE with the initial arguments: the core counter for the old identifier went negative, so remounting with those arguments summed to zero and the subscription never resolved, while the active identifier leaked without unsubscribe.
    Rework the hook into a single effect keyed on the normalized query/variables state, so every cycle subscribes, listens and cleans up with the same arguments. This also stops stale BBB_CORE_SENT_NEW_DATA listeners from piling up on resubscribe. Custom queries keep their mount-time arguments, as before.
  • Unit tests run with vitest + testing-library via npm run test:unit, living under tests/unit/ (mirroring the src/ tree) instead of
    alongside the source files, and ignored by the Playwright runner. Shared query and type fixtures live in tests/unit/queries.ts and tests/unit/types.ts, following the same convention as the e2e fixtures under tests/core/.
    The suite locks the data-consumption hook contracts: subscribe and unsubscribe events balance per identifier across mount, variable changes and unmount (useCustomSubscription stuck in loading: true state #275); every mount emits a fresh subscribe with the data listener registered beforehand so resubscribing after a full unsubscribe still resolves ([Plugins] Inconsistent hook component remounting due to subscription count-based keys bigbluebutton#23814); re-dispatched unchanged data is applied idempotently and shared subscriptions stay stable across rerenders (Bug: useCustomSubscription changes loading value indefinitely  #251); custom queries keep their mount-time arguments.

Closes Issue(s)

Closes #275

Motivation

Adding unit tests to the data consumption engine helps ensure we're not fixing one bug while introducing a regression in another that was already fixed, since this is one of the most complex and frequently modified areas of the codebase.

Arthurk12 and others added 3 commits July 22, 2026 21:00
createDataConsumptionHook kept its unmount cleanup in a mount-only
effect, closing over the first render's query/variables. After a
custom subscription changed variables, unmount dispatched
PLUGIN_UNSUBSCRIBED_FROM_BBB_CORE with the initial arguments: the
core counter for the old identifier went negative, so remounting
with those arguments summed to zero and the subscription never
resolved, while the active identifier leaked without unsubscribe.

Rework the hook into a single effect keyed on the normalized
query/variables state, so every cycle subscribes, listens and
cleans up with the same arguments. This also stops stale
BBB_CORE_SENT_NEW_DATA listeners from piling up on resubscribe.
Custom queries keep their mount-time arguments, as before.
Unit tests run with vitest + testing-library via npm run test:unit,
living under tests/unit/ (mirroring the src/ tree) instead of
alongside the source files, and ignored by the Playwright runner.
Shared query and type fixtures live in tests/unit/queries.ts and
tests/unit/types.ts, following the same convention as the e2e
fixtures under tests/core/.

The suite locks the data-consumption hook contracts: subscribe and
unsubscribe events balance per identifier across mount, variable
changes and unmount (bigbluebutton#275); every mount emits a fresh subscribe with
the data listener registered beforehand so resubscribing after a
full unsubscribe still resolves (bigbluebutton/bigbluebutton#23814);
re-dispatched unchanged data is applied idempotently and shared
subscriptions stay stable across rerenders (bigbluebutton#251); custom queries
keep their mount-time arguments.

Refs bigbluebutton#275, bigbluebutton#251, bigbluebutton/bigbluebutton#23814
tests/tsconfig.json had no include/exclude, so once tests/unit/
started importing src/ modules it pulled the whole SDK into the
same TypeScript program as tests/core/. That collided two unrelated
things:

- tests/core/helpers.ts declares a global `Window.meetingClientSettings`
  override for Playwright's page.evaluate calls; merged with
  src/core/api/types.ts's own PluginBrowserWindow (which extends
  Window with an optional, differently-shaped meetingClientSettings),
  TypeScript raised a global interface merge conflict.
- Its ancient target (es5) with no skipLibCheck choked on the newer
  syntax used by vitest/vite/rollup's own .d.ts files once vitest
  entered the program.

tests/tsconfig.json now excludes tests/unit/ and stays scoped to the
e2e helpers it was written for (plus skipLibCheck, which was already
needed for the pre-existing playwright-core lib errors). tests/unit/
gets its own tsconfig.json instead of sharing one with the Playwright
suite, so unit and e2e tests never share a program again.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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