()
| 31 | }; |
| 32 | |
| 33 | export const useLayoutVariant = (): UseLayoutVariant => { |
| 34 | const serverVariant = useContext(LayoutVariantContext); |
| 35 | const { isAuthReady } = useAuthContext(); |
| 36 | const isLaptop = useViewSize(ViewSize.Laptop); |
| 37 | const { isV2, isLoading } = useLayoutVariantFlag(); |
| 38 | |
| 39 | // The shell the mirrored route painted stands only until the flag can |
| 40 | // contradict it, so turning `layout_v2` off takes effect on this render |
| 41 | // rather than the next hard navigation. `isLaptop` is client-only and would |
| 42 | // contradict what the server painted, so it applies from the second render |
| 43 | // on: `isAuthReady` is false on the server and on the first client render, |
| 44 | // which makes it the hydration boundary. |
| 45 | if (serverVariant && isLoading) { |
| 46 | return { |
| 47 | isV2: serverVariant === 'v2' && (!isAuthReady || isLaptop), |
| 48 | isLoading: false, |
| 49 | }; |
| 50 | } |
| 51 | |
| 52 | return { isV2, isLoading: serverVariant ? false : isLoading }; |
| 53 | }; |
no test coverage detected