Repository navigation
Conversation
… on every resize A media feature compared with the window's size (min-width, max-width, width ranges, height, orientation) read `vw`/`vh` directly, so every component with a media query subscribed its rules to the window's exact size. A window resized live changes that size on every frame: every such component re-ran its rules and re-rendered on every frame, though no query's answer changed (Tailwind's sm:/md:/lg: variants are on most of an app's elements). Each comparison is now an observable of its answer (windowQueryFamily), derived from vw/vh: it notifies only when the answer flips, so a resize re-renders a component once, when it crosses one of its breakpoints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 31, 2026
This branch has not been deployed
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.
Problem
A media feature compared with the window's size (
min-width,max-width,width/heightranges,orientation) readvwandvhdirectly intestMediaQuery. That subscribed every component with a media query to the window's exact size. During a live window resize (desktop windows, iPad split view, an Android freeform window),Dimensionschanges on every frame. So every such component re-ranupdateRulesand re-rendered on every frame, even though no query's answer had changed.Tailwind's
sm:/md:/lg:variants sit on many of an app's elements, so this adds up to a large share of the JavaScript in each resize frame. We measured it on a React Native host (OxyOS, Fabric) resizing a file browser built with NativeWind v5: several styled elements re-rendered on every frame while the window crossed no breakpoint.Change
Each comparison is now an observable of its answer.
windowQueryFamilyholds one per query key (vw>=640,vh<=500,landscape, …), derived fromvw/vh. Its defaultObject.isequality means it notifies only when the boolean flips.testMediaQueryreads that observable instead of the raw size. During a resize, the derived observable recomputes a comparison per frame, and the rule effects only run when a component crosses one of its breakpoints.Nothing else changes.
vw/vhunits in declarations still follow the size continuously,resolutionstill readsPixelRatio, and every existing media-query test passes unchanged.Test
media-query.test.tsxhas a new test, "a resize re-renders a media query's element only when the query's answer changes". It wraps two elements (one with a matchingmin-widthquery, one with a non-matching one) in aProfiler, steps the width through seven values that cross no breakpoint, and expects no commits. Then it crosses one breakpoint and expects a re-render with the new style, and no further commits as the width keeps changing on the same side.tscandeslintare clean.🤖 Generated with Claude Code