Repository navigation
refactor(web): forceable phone mode for the responsive switch - #1437
Conversation
|
I pushed this PR before its local review ran. Round 1 has now run at
The fix applies the P3 simplification, which also removes the untested override. The nullable hook and |
Remove setPhoneModeForTests and the Dialog override; seam tests now pick phone or desktop with the existing stubMatchMedia helper, reset by the shared vi.unstubAllGlobals cleanup. Drop the window-undefined check: the app has no SSR path.
|
Screenshots from a real browser. Captured at I built two isolated sim stacks from scratch, one per commit, and signed in through the login form as the Meadowlark (readme-farm) Owner. The viewport, user, data and screen are the same in each pair. Every frame is 1:1, light theme.
No pair differs. A pixel diff of each before and after file found no changed pixel. In the live switch I resized the same page from 899px to 900px. A marker set on The only console error on any page was the sign-in page's 401 session probe on a fresh browser context, which every run against a healthy stack shows. |












This PR prepares the jsdom 31 upgrade (#1426). I chose to refactor first and upgrade second. After this PR, tests can pick the phone or desktop layout.
What
usePhoneMode(): boolean | nulllives inlib/breakpoints.ts, next toMD_UP_QUERY, the single boundary constant for the switch.nullmeans nothing can determine the mode, because the host has nomatchMedia(jsdom 30 is one such host). Call sites then keep the existingsx={{ display: { xs, md } }}media query, so behavior under jsdom 30 is unchanged.trueorfalseis the result of MUIuseMediaQuery(MD_UP_QUERY). In a browser it follows the viewport. In tests, the existingstubMatchMediahelper (src/test/matchMedia.ts) sets it, and the sharedvi.unstubAllGlobals()cleanup resets it after each test.phoneModeDisplayholds the null rule in one place.Converted switches: the AppLayout sidebar, the BottomNav tab bar and AuthShell's nextStep panels. Dialog is unchanged. Its
fullScreenOnPhonedecision still readsuseMediaQuery(MD_UP_QUERY)directly, andstubMatchMediaalready controls that. Layout-only switches (the FieldConsole grid, the CustomersPage column) stay media-based.Why
jsdom 31 evaluates CSS media queries against a frozen 1024×768 viewport. Its CSS environment is a fixed
Object.freezed value, so tests cannot change it. Under jsdom 31 the tab bar is alwaysmd: "none", and 98 tests fail with no way to reach the phone layout. AmatchMediastub cannot change how jsdom applies@mediarules, so the switch needs a literaldisplayvalue when the mode is known. The jsdom bump itself is the follow-up PR that closes #1426.A probe in the jsdom 31 worktree confirmed this. On 31,
@mediarules apply at 1024px. On 30, jsdom ignores all@mediarules, so phone CSS never applied in tests before either.Verification
npm run typecheck: 0 errorsnpm run test: 184 files, 4,428 tests. Main has 183 files and 4,425 tests. The 3 new cases are inphoneModeSeam.test.tsx: phone, desktop, and nomatchMedia(both navs stay rendered).npm run lintnpm run buildMutations, each reverted:
usePhoneModealways returns null: the phone and desktop cases fail.Docs-impact: none — behavior-preserving refactor; no user-visible strings or help content change.