Skip to content

Commit 9ea059c

Browse files
authored
fix: dismiss all sheets created by RCTDevLoadingView when hide is called (#2448)
## Summary: We've had a recurring bug where `RCTDevLoadingView` stick around blocking the whole app even after it's dismissed. As far as I can tell, this is a race condition where we have multiple devloadingviews at once (each setting and nilling the same `self->_window` property), which is causing a race condition. Rather than figure out how to make this class only ever show one window or race-safe, for now I will just make sure to dismiss _all_ sheets when `hide` is called. While we're at it, a couple of other changes: 1. Change the type from `NSPanel` to `NSWindow`. Panels don't release when closed, which may be causing them to stick around longer than we like 2. Move the iOS only variable `mainWindow` into the iOS ifdef, and remove the diffs and diff tag around it. ## Test Plan: Initial testing shows RNTester no longer getting blocked. It could still happen (race conditions are hard), but I think the change is safe to add regardless.
1 parent 1129083 commit 9ea059c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/react-native/React/CoreModules/RCTDevLoadingView.mm

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
using namespace facebook::react;
2626

27+
static NSString *sRCTDevLoadingViewWindowIdentifier = @"RCTDevLoadingViewWindow";
28+
2729
@interface RCTDevLoadingView () <NativeDevLoadingViewSpec>
2830
@end
2931

@@ -121,16 +123,17 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
121123

122124
self->_showDate = [NSDate date];
123125

124-
RCTPlatformWindow *mainWindow = RCTKeyWindow(); // [macOS]
125126
#if !TARGET_OS_OSX // [macOS]
127+
UIWindow *mainWindow = RCTKeyWindow();
126128
self->_window = [[UIWindow alloc] initWithWindowScene:mainWindow.windowScene];
127129
self->_window.windowLevel = UIWindowLevelStatusBar + 1;
128130
self->_window.rootViewController = [UIViewController new];
129131
#else // [macOS
130-
self->_window = [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 375, 20)
132+
self->_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 375, 20)
131133
styleMask:NSWindowStyleMaskBorderless
132134
backing:NSBackingStoreBuffered
133135
defer:YES];
136+
[self->_window setIdentifier:sRCTDevLoadingViewWindowIdentifier];
134137
#endif // macOS]
135138

136139
self->_container = [[RCTUIView alloc] init]; // [macOS]
@@ -220,7 +223,11 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
220223
self->_hiding = false;
221224
}];
222225
#else // [macOS]
223-
[RCTKeyWindow() endSheet:self->_window];
226+
for (NSWindow *window in [RCTKeyWindow() sheets]) {
227+
if ([[window identifier] isEqualToString:sRCTDevLoadingViewWindowIdentifier]) {
228+
[RCTKeyWindow() endSheet:window];
229+
}
230+
}
224231
self->_window = nil;
225232
self->_hiding = false;
226233
#endif // macOS]
@@ -350,4 +357,4 @@ - (void)hide
350357
Class RCTDevLoadingViewCls(void)
351358
{
352359
return RCTDevLoadingView.class;
353-
}
360+
}

0 commit comments

Comments
 (0)