Skip to content

Commit afffb9c

Browse files
authored
Merge pull request #3854 from bobleer/bob/fix-welcome-text-overlap
fix(web-ui): keep welcome brand and tagline from overlapping
2 parents 2c29b5f + b5a7431 commit afffb9c

3 files changed

Lines changed: 82 additions & 14 deletions

File tree

‎src/web-ui/src/app/scenes/welcome/WelcomeScene.scss‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
min-width: 0;
1212
min-height: 0;
1313
overflow: hidden;
14-
container-type: inline-size;
1514
background: var(--openbitfun-color-surface-scene);
1615

1716
&__content {
@@ -133,32 +132,35 @@
133132
50% { opacity: 0; }
134133
}
135134

136-
@container (max-width: 560px) {
137-
.welcome-scene {
138-
&__content {
135+
// Width tiers come from `data-density` (set by WelcomeScene from a
136+
// ResizeObserver), not container queries; see the component for why.
137+
.welcome-scene {
138+
&[data-density='compact'],
139+
&[data-density='tiny'] {
140+
.welcome-scene__content {
139141
padding-inline: var(--openbitfun-space-4);
140142
}
143+
}
141144

142-
&__brand,
143-
&__tagline {
145+
&[data-density='compact'] {
146+
.welcome-scene__brand,
147+
.welcome-scene__tagline {
144148
font-size: var(--openbitfun-type-heading-display-font-size);
145149
}
146150

147-
&__logo {
151+
.welcome-scene__logo {
148152
width: 48px;
149153
height: 48px;
150154
}
151155
}
152-
}
153156

154-
@container (max-width: 400px) {
155-
.welcome-scene {
156-
&__brand,
157-
&__tagline {
157+
&[data-density='tiny'] {
158+
.welcome-scene__brand,
159+
.welcome-scene__tagline {
158160
font-size: var(--openbitfun-type-flow-title-font-size);
159161
}
160162

161-
&__logo {
163+
.welcome-scene__logo {
162164
width: 36px;
163165
height: 36px;
164166
}

‎src/web-ui/src/app/scenes/welcome/WelcomeScene.test.tsx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,32 @@ describe('welcome startup timing', () => {
9595
await act(async () => { await vi.advanceTimersByTimeAsync(5000); });
9696
expect(phrase()).toBe(initial);
9797
});
98+
99+
it('switches the type scale through a width attribute, not container queries', () => {
100+
let notify: ((entries: Array<{ contentRect: { width: number } }>) => void) | undefined;
101+
const disconnect = vi.fn();
102+
vi.stubGlobal('ResizeObserver', class {
103+
constructor(callback: typeof notify) { notify = callback; }
104+
observe() {}
105+
disconnect = disconnect;
106+
});
107+
act(() => root.render(<WelcomeScene />));
108+
const scene = container.querySelector('section')!;
109+
// jsdom lays out nothing, so a zero width must keep the regular tier.
110+
expect(scene.dataset.density).toBe('regular');
111+
112+
// Startup or a resize can lay the scene out narrow before it widens.
113+
act(() => notify!([{ contentRect: { width: 360 } }]));
114+
expect(scene.dataset.density).toBe('tiny');
115+
act(() => notify!([{ contentRect: { width: 520 } }]));
116+
expect(scene.dataset.density).toBe('compact');
117+
act(() => notify!([{ contentRect: { width: 0 } }]));
118+
expect(scene.dataset.density).toBe('compact');
119+
act(() => notify!([{ contentRect: { width: 1200 } }]));
120+
expect(scene.dataset.density).toBe('regular');
121+
122+
act(() => root.unmount());
123+
expect(disconnect).toHaveBeenCalled();
124+
root = createRoot(container);
125+
});
98126
});

‎src/web-ui/src/app/scenes/welcome/WelcomeScene.tsx‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SceneViewport until the user opens a scene.
44
*/
55

6-
import React, { useEffect, useMemo, useState } from 'react';
6+
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
77
import { useI18n } from '@/infrastructure/i18n';
88
import { isReducedMotionPreferred } from '@/shared/utils/motionPreference';
99
import { OpenBitFunMark } from '@openbitfun/ui/brand';
@@ -16,10 +16,22 @@ const DELETE_MS = 55;
1616
const PHRASE_HOLD_MS = 2200;
1717
const PHRASE_GAP_MS = 450;
1818
const YOUR_WORD_INDEX = 2;
19+
const COMPACT_MAX_WIDTH = 560;
20+
const TINY_MAX_WIDTH = 400;
21+
22+
type WelcomeDensity = 'regular' | 'compact' | 'tiny';
23+
24+
function densityForWidth(width: number): WelcomeDensity {
25+
if (width <= TINY_MAX_WIDTH) return 'tiny';
26+
if (width <= COMPACT_MAX_WIDTH) return 'compact';
27+
return 'regular';
28+
}
1929

2030
const WelcomeScene: React.FC = () => {
2131
const { t } = useI18n('common');
32+
const sceneRef = useRef<HTMLElement>(null);
2233
const [text, setText] = useState('');
34+
const [density, setDensity] = useState<WelcomeDensity>('regular');
2335
const [reducedMotion, setReducedMotion] = useState(isReducedMotionPreferred);
2436
const [startupEntry] = useState(isStartupOverlayPresent);
2537
const [startupPending, setStartupPending] = useState(startupEntry);
@@ -44,6 +56,30 @@ const WelcomeScene: React.FC = () => {
4456
[impossible, dreams, your, suffix, think, ideas, create, explore],
4557
);
4658

59+
// The type scale follows the scene width through a plain attribute instead of
60+
// CSS container queries. WebKit resolves container queries inside layout and
61+
// can keep stale inline positions for the `white-space: pre` brand text when
62+
// the scene first lays out narrow (startup, window resize) and then widens:
63+
// the glyphs repaint at the larger size while the tagline stays where the
64+
// smaller text ended, so the two lines overlap. An attribute change goes
65+
// through ordinary style invalidation before layout, which re-measures text.
66+
useLayoutEffect(() => {
67+
const scene = sceneRef.current;
68+
if (!scene) return;
69+
const apply = (width: number) => {
70+
// A hidden or detached scene reports zero; keep the last real tier.
71+
if (width > 0) setDensity(densityForWidth(width));
72+
};
73+
apply(scene.getBoundingClientRect().width);
74+
if (typeof ResizeObserver === 'undefined') return;
75+
const observer = new ResizeObserver(entries => {
76+
const entry = entries[entries.length - 1];
77+
if (entry) apply(entry.contentRect.width);
78+
});
79+
observer.observe(scene);
80+
return () => observer.disconnect();
81+
}, []);
82+
4783
useEffect(() => {
4884
if (!startupPending) return;
4985
const handleHandoff = () => setStartupPending(false);
@@ -107,10 +143,12 @@ const WelcomeScene: React.FC = () => {
107143

108144
return (
109145
<section
146+
ref={sceneRef}
110147
className="welcome-scene"
111148
data-testid="welcome-scene"
112149
data-openbitfun-scene="welcome"
113150
data-openbitfun-part="root"
151+
data-density={density}
114152
data-startup-entry={startupEntry ? '' : undefined}
115153
data-startup-pending={startupPending ? '' : undefined}
116154
aria-labelledby="welcome-scene-title"

0 commit comments

Comments
 (0)