Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix useFacetCallback mismatch subscriptions #115

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

pirelenito
Copy link
Member

@pirelenito pirelenito commented Mar 6, 2023

After the fix of #114, it introduced a new bug that would cause the callback to never being able to be called since useFacetCallback would internally might no longer have a facet with an active subscription.

The new bug was caused by using a shared noop instance across all usages of useFacetCallback, and it occurs because our createFacet implementation uses a given listener instance as a key to keep track of all its listeners. See: https://github.com/Mojang/ore-ui/blob/main/packages/%40react-facet/core/src/facet/createFacet.ts#L17

The fix makes sure that we don't reuse the same instance, with a accompanying unit test.

In the future we might want to review our decision of using a Set as it can potentially introduce issues such as this one. There has been some work on this front, but it comes with other challenges as well (potentially on performance and supporting unsubscribing as events are firing).

@pirelenito pirelenito requested review from a team and xaviervia and removed request for a team March 6, 2023 12:28
@pirelenito pirelenito merged commit b16c53e into main Mar 6, 2023
@pirelenito pirelenito deleted the fix-use-facet-callback-unsubscriptions branch March 6, 2023 13:00
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