fix(MatrixRTCSession): replace no-arg .finally() with .then(fn, fn) to fix crash on React Native / Hermes#5307
Open
JeanLuX wants to merge 2 commits intomatrix-org:developfrom
Open
Conversation
…ejected) to fix crash on React Native / Hermes Calling .finally() without an argument works in browsers and Node.js but throws a TypeError on Hermes (the JS engine used by React Native): TypeError: undefined is not a function This happens because the React Native Promise polyfill requires the onFinally argument to be a function. When it receives undefined it throws immediately, before recalculateSessionMembers() even runs. The crash fires once per room at startup (via MatrixRTCSessionManager.start()) and leaves every MatrixRTCSession's initialMembershipCalculated promise permanently rejected, silently breaking RTC session management on all React Native clients. Fix: replace the no-arg .finally().then(fn) pattern with an explicit two-handler .then(onFulfilled, onRejected) that achieves identical semantics — run recalculateSessionMembers() whether the previous promise resolved or rejected — while being safe on all runtimes. Signed-off-by: Jean-Luc Cenatus <contact@jcenatus.net>
…ionMembers after rejection Verify that ensureRecalculateSessionMembers() still runs correctly even when recalculateSessionMembersPromise is in a rejected state. This guards against the React Native / Hermes regression where the previous .finally() call (no argument) threw a TypeError and left the promise chain permanently broken. Signed-off-by: Jean-Luc Cenatus <contact@jcenatus.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5308
What
ensureRecalculateSessionMembers()called.finally()with no argument to swallow a previous rejection before chaining the next recalculation.On React Native / Hermes, the RN Promise polyfill (
promise/setimmediate/finally.js) requiresonFinallyto be a callable — passingundefinedthrows immediately:This rejects
initialMembershipCalculatedfor every room at startup, silently breaking the entire RTC session membership layer on all React Native clients.Fix
Replace
.finally().then(fn)with.then(fn, fn)— semantically equivalent on all runtimes:File:
src/matrixrtc/MatrixRTCSession.ts—ensureRecalculateSessionMembers()Verified on
Checklist
yarn test)