-
Notifications
You must be signed in to change notification settings - Fork 5
fix(runtime): avoid HMRClient.disable startup race #38
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
base: main
Are you sure you want to change the base?
fix(runtime): avoid HMRClient.disable startup race #38
Conversation
React Native may throw "Expected HMRClient.setup()" if disable() runs before setup(). Retry disable() briefly on that specific invariant so harness startup stays stable. Add a unit test for the retry helper.
|
@bheemreddy-samsara is attempting to deploy a commit to the Callstack Team on Vercel. A member of the Team first needs to authorize it. |
|
@V3RON Can you review this ? |
|
I wonder if it wouldn't be more bulletproof to monkey-patch HMRClient and override the .setup method so it does nothing, then call .disable() afterward (just to be sure), all wrapped in a try/catch to swallow any potential errors. That would remove the need for retries and make the whole flaky setTimeout obsolete. WDYT? |
I considered monkey-patching |
In fact, we should block the Harness setup. HMRClient should be disabled before any tests run, because if you start a Harness run and modify test files at the same time, Metro will push updates to the runtime, causing issues. |
Ensure we only report harness ready after HMR has been disabled. This prevents Metro from pushing updates mid-run if tests change during execution.
|
Good call — updated.
So harness won't start executing tests / report ready until HMR is off, preventing Metro updates mid-run. (Also added/updated a unit test for the Promise-based retry behavior.) |
|
is this approach good to move forward ? @V3RON |
Problem
On some apps, harness runs can intermittently fail at startup with a redbox:
Root cause:
@react-native-harness/runtimeschedulesHMRClient.disable()on a timer, but React Native hasn't always invokedHMRClient.setup()yet, so RN throws and the harness never reports ready.Fix
disableHMRWhenReadyhelper that retriesdisable()when it fails with the specific RN invariant, then succeeds once setup is complete.HMRClient.Tests
Validation
pnpm nx test @react-native-harness/runtimepnpm nx lint @react-native-harness/runtimepnpm nx typecheck @react-native-harness/runtimepnpm nx build @react-native-harness/runtime