mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 07:26:19 +00:00
Hoist usePollSubscriptions to RoomWidgetsView; drop the side effect from usePollWidget
Follow-up to the previous commit's poll split. The compat shim
usePollWidget used to call usePollSubscriptions() inside its body so
the three RoomSessionPollEvent listeners were still registered for
existing consumers — but that meant:
- listeners would be re-registered per consumer (today nobody, since
useWordQuizWidget was already migrated to usePollActions);
- the lifetime of the subscriptions was tied to a leaf widget instead
of the room session;
- a render of a component using the shim had the side effect of
attaching three global event listeners.
Move
- src/components/room/widgets/RoomWidgetsView.tsx now calls
usePollSubscriptions() once at the top of the room-widget tree. The
bridge from RoomSessionPollEvent (OFFER/ERROR/CONTENT) to the UI
event bus is now mounted for exactly the lifetime of an in-room
session, regardless of which leaf widget renders.
- src/hooks/rooms/widgets/usePollWidget.ts (compat shim) is reduced
to a one-liner that just returns usePollActions(). It is still
deprecated; remove once nothing imports it.
Verification
- yarn eslint on the two touched files: 1 pre-existing error
(the same FC<{}> in RoomWidgetsView that was there before — baseline
unchanged; I deliberately did not touch it in this commit to keep
the diff minimal).
- yarn test: 22/22 still passing.
- grep confirms usePollWidget has zero in-tree consumers; the only
importer is the barrel re-export.
This commit is contained in:
@@ -1,17 +1,12 @@
|
||||
import { usePollActions } from './usePollActions';
|
||||
import { usePollSubscriptions } from './usePollSubscriptions';
|
||||
|
||||
/**
|
||||
* @deprecated Prefer `usePollSubscriptions` (mount once, top-level) and
|
||||
* `usePollActions` (anywhere a component dispatches a vote/accept/reject).
|
||||
* This shim preserves the old `{ startPoll, rejectPoll, answerPoll }`
|
||||
* shape for existing consumers, but each call also re-mounts the three
|
||||
* subscription listeners — which is wrong if the hook is called from
|
||||
* multiple places.
|
||||
* @deprecated Prefer `usePollActions` for components that dispatch
|
||||
* votes/accepts/rejects. The corresponding subscriptions are now mounted
|
||||
* once by `RoomWidgetsView` via `usePollSubscriptions`, so this shim no
|
||||
* longer needs to register them transitively.
|
||||
*
|
||||
* Kept only to preserve the `{ startPoll, rejectPoll, answerPoll }`
|
||||
* shape for any out-of-tree consumer; remove once nothing imports it.
|
||||
*/
|
||||
export const usePollWidget = () =>
|
||||
{
|
||||
usePollSubscriptions();
|
||||
|
||||
return usePollActions();
|
||||
};
|
||||
export const usePollWidget = () => usePollActions();
|
||||
|
||||
Reference in New Issue
Block a user