Fix auto-resize destroying horizontal scroll positions#567
Draft
mel-anthropic wants to merge 2 commits intomodelcontextprotocol:mainfrom
Draft
Fix auto-resize destroying horizontal scroll positions#567mel-anthropic wants to merge 2 commits intomodelcontextprotocol:mainfrom
mel-anthropic wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
The setupSizeChangedNotifications method temporarily sets html.style.width to 'fit-content' to measure intrinsic content width. For responsive apps that derive width from their container (width: 100%, flex: 1, etc.), fit-content resolves to 0px. The synchronous reflow at 0px causes browsers to clamp scrollLeft on all horizontal scroll containers to 0, permanently destroying their scroll positions. Replace the fit-content width measurement with window.innerWidth. The height measurement (max-content) is preserved since hosts rely on it. Neither the iOS nor web host uses the width value from size-changed notifications, so this change has no functional impact on hosts while fixing scroll position clamping for all MCP apps with horizontal scroll views.
@modelcontextprotocol/ext-apps
@modelcontextprotocol/server-basic-preact
@modelcontextprotocol/server-basic-react
@modelcontextprotocol/server-basic-solid
@modelcontextprotocol/server-basic-svelte
@modelcontextprotocol/server-basic-vanillajs
@modelcontextprotocol/server-basic-vue
@modelcontextprotocol/server-budget-allocator
@modelcontextprotocol/server-cohort-heatmap
@modelcontextprotocol/server-customer-segmentation
@modelcontextprotocol/server-debug
@modelcontextprotocol/server-map
@modelcontextprotocol/server-pdf
@modelcontextprotocol/server-scenario-modeler
@modelcontextprotocol/server-shadertoy
@modelcontextprotocol/server-sheet-music
@modelcontextprotocol/server-system-monitor
@modelcontextprotocol/server-threejs
@modelcontextprotocol/server-transcript
@modelcontextprotocol/server-video-resource
@modelcontextprotocol/server-wiki-explorer
commit: |
Hosts determine the container size in fullscreen mode, so size-changed notifications are not needed. The temporary max-content height override used for measurement causes visible vertical jitter during animated fullscreen transitions by briefly reflowing the document on every frame.
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.
Summary
Fix two issues in the SDK's auto-resize measurement that cause visual glitches during viewport transitions (e.g. inline ↔ fullscreen).
Changes
Fix horizontal scroll position destruction
setupSizeChangedNotifications()temporarily setsdocument.documentElement.style.width = 'fit-content'on everyResizeObservercallback to measure intrinsic content width. For responsive apps that derive their width from the container (width: 100%,flex: 1, etc.),fit-contentresolves to 0px.The
getBoundingClientRect()call forces a synchronous reflow at 0px width. During this reflow, the browser clampsscrollLefton all horizontal scroll containers to 0 (sincescrollLeftcannot exceedscrollWidth - clientWidth, which is 0). When the style is restored,scrollLeftstays clamped — the browser does not un-clamp it.This manifests as horizontal scroll views losing their position whenever the viewport resizes, which is most visible during inline ↔ fullscreen transitions.
Fix: Replace the
fit-contentwidth measurement withwindow.innerWidth. The height measurement (max-content) is preserved since hosts rely on it. Neither the iOS nor web host uses thewidthvalue fromsize-changednotifications — both only consumeheight— so this change has no functional impact on hosts.Skip size-changed measurement during fullscreen
Hosts determine the container size in fullscreen mode, so
size-changednotifications are not needed. The temporarymax-contentheight override used for measurement causes visible vertical jitter during animated fullscreen transitions by briefly reflowing the document on every animation frame.Fix: Skip measurement entirely when
hostContext.displayMode === "fullscreen". Verified that all three hosts (iOS, Android, Web) ignore thesize-changedheight value for layout during fullscreen.Testing
scrollLeftdropped from 6406 to 772 when entering fullscreen before the fix; stays stable after