Skip to content

Commit f3650be

Browse files
Saadnajmiclaude
andcommitted
fix(fabric): fix Text overflow in ScrollView on first render (macOS)
On macOS, the _containerView (NSScrollView's documentView) has autoresizingMask set so it fills the visible area before React's first layout pass. However, AppKit's autoresizing corrupts the documentView's frame by adding the NSClipView's size delta to the container's dimensions (e.g., during initial tile or window attachment), inflating it well beyond the correct content size and producing massive horizontal and vertical overflow on first render. The fix adds a layoutSubviews override on macOS that resets the documentView frame to the correct React-managed content size after AppKit's layout pass (which triggers autoresizing). This corrects the corruption while preserving the autoresizingMask needed for the documentView to fill the visible area before React's first updateState. Fixes #2857 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 70f3149 commit f3650be

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,30 @@ - (void)dealloc
184184
#endif // [macOS]
185185
}
186186

187+
#if TARGET_OS_OSX // [macOS
188+
- (void)layoutSubviews
189+
{
190+
[super layoutSubviews];
191+
192+
// On macOS, the _containerView is the NSScrollView's documentView and has autoresizingMask set so
193+
// it fills the visible area before React's first layout pass. However, AppKit's autoresizing can
194+
// corrupt the documentView's frame by adding the NSClipView's size delta to the container's
195+
// dimensions (e.g., during initial tile or window resize), inflating it well beyond the correct
196+
// content size. This produces massive horizontal and vertical overflow on first render.
197+
//
198+
// After React has set the content size via updateState:, we reset the documentView frame here to
199+
// undo any autoresizing corruption. This runs after AppKit's layout (which triggers autoresizing),
200+
// so it reliably corrects the frame.
201+
if (!CGSizeEqualToSize(_contentSize, CGSizeZero)) {
202+
CGRect containerFrame = _containerView.frame;
203+
if (!CGSizeEqualToSize(containerFrame.size, _contentSize)) {
204+
containerFrame.size = _contentSize;
205+
_containerView.frame = containerFrame;
206+
}
207+
}
208+
}
209+
#endif // macOS]
210+
187211
#if TARGET_OS_IOS
188212
- (void)_registerKeyboardListener
189213
{

0 commit comments

Comments
 (0)