Commit b60a73d
Replace userId-only iframe context with combined guardian-puzzle-context
Per confirmed PR review feedback: replace the userId-only query
param/postMessage mechanism with a single, richer PuzzleContext carrying
both the user's ID and whether dark mode is currently active.
- src/components/PuzzleIframe.island.tsx:
- New PuzzleContext type: { userId: string | null; darkMode: boolean }.
userId is the same source as before (legacy_identity_id via
getAuthStatus()) but now string | null (null for signed-out) rather
than string | undefined, since it's now always a serialized object
field rather than an omitted query param.
- New PuzzleContextMessage type ({ type: 'guardian-puzzle-context',
context }), replacing the old PuzzleUserMessage
({ type: 'guardian-puzzle-user', userId }).
- New usePuzzleDarkMode(darkModeAvailable) hook: returns false
immediately (without touching matchMedia at all) when
darkModeAvailable is false; otherwise reuses the EXISTING generic
src/lib/useMatchMedia.ts hook (already used elsewhere in DCR, e.g.
ArticleMeta.web.tsx) to check - and stay reactively subscribed to -
'(prefers-color-scheme: dark)', so it updates live if the reader
switches their OS theme while the page is open. No new matchMedia
wiring was invented; this is the same reactive mechanism DCR already
has, just applied here.
- buildPuzzleIframeSrc -> buildPuzzleIframeSrcWithContext: now encodes
the whole PuzzleContext as JSON into a single
?guardian-puzzle-context=<encoded> query param, always included (the
old mechanism omitted ?userId entirely when signed out; the new
shape always carries both fields, so there's no "nothing to add"
case). Still preserves existing query params (e.g. AmuseLabs'
?set=...&embed=1&idx=1) and still returns src unchanged if it can't
be parsed as an absolute URL.
- postUserMessage -> postContextMessage: posts the new
PuzzleContextMessage shape on iframe load. Unchanged behaviour
otherwise - src is derived reactively from both usePuzzleUserId() and
usePuzzleDarkMode(), so a change in either sign-in state or OS colour
scheme causes a fresh src and a natural iframe reload, with
postMessage firing again after.
- PuzzleIframe now takes a new required darkModeAvailable: boolean prop.
- src/layouts/PuzzlePageLayout.tsx / src/components/PuzzlePage.tsx:
threaded darkModeAvailable down from PuzzlePage.tsx's existing
useConfig() (the same flag already passed to rootStyles() for the page
chrome's own dark mode support) through PuzzlePageLayout to
PuzzlePageContent to PuzzleIframe - no new source of truth introduced,
reusing the config value that already existed for this exact purpose.
- src/components/PuzzleIframe.island.test.tsx: rewritten (not just
renamed) to cover the new context shape and, specifically, dark-mode
reactivity: userId: null + darkMode: false while signed out with dark
mode unavailable; userId populated once signed in; darkMode staying
false when darkModeAvailable is false regardless of the OS preference
(confirming prefers-color-scheme is never even consulted in that case);
darkMode true only when both darkModeAvailable AND the (mocked)
useMatchMedia result are true; a live-reactivity test simulating an
OS-level colour-scheme change via a re-render with a new mocked
useMatchMedia value, matching this codebase's existing convention of
mocking useMatchMedia at the module boundary (see
ArticleMeta.web.test.tsx, PuzzlePageLayout.test.tsx) rather than mocking
window.matchMedia directly; postMessage now asserted with the new
PuzzleContextMessage shape; auth-state-change subscription and unmount
cleanup tests carried over, updated for the new context shape.
- src/layouts/PuzzlePageLayout.test.tsx: added the new required
darkModeAvailable prop (false, matching its existing
ConfigProvider/darkModeAvailable: false setup).
Verified manually against a live dev server: POSTing a fixture renders
200, and the server-rendered iframe src correctly contains
guardian-puzzle-context=%7B%22userId%22%3Anull%2C%22darkMode%22%3Afalse%7D
(decodes to {"userId":null,"darkMode":false}), the expected default before
client-side hydration resolves the real auth/media-query state.
tsc --noEmit clean, full-repo eslint clean, full test suite passing
(175 suites / 1268 tests, no regressions).
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>1 parent 3a800b6 commit b60a73d
5 files changed
Lines changed: 286 additions & 86 deletions
File tree
- dotcom-rendering/src
- components
- layouts
Lines changed: 169 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
6 | 11 | | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
13 | 22 | | |
| 23 | + | |
14 | 24 | | |
15 | 25 | | |
16 | 26 | | |
| |||
22 | 32 | | |
23 | 33 | | |
24 | 34 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 35 | + | |
| 36 | + | |
31 | 37 | | |
32 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
33 | 41 | | |
34 | | - | |
35 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
36 | 47 | | |
37 | 48 | | |
38 | | - | |
| 49 | + | |
| 50 | + | |
39 | 51 | | |
40 | | - | |
| 52 | + | |
41 | 53 | | |
42 | | - | |
| 54 | + | |
43 | 55 | | |
44 | 56 | | |
45 | | - | |
| 57 | + | |
46 | 58 | | |
47 | 59 | | |
48 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
49 | 71 | | |
50 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
51 | 78 | | |
52 | 79 | | |
53 | 80 | | |
| |||
58 | 85 | | |
59 | 86 | | |
60 | 87 | | |
| 88 | + | |
61 | 89 | | |
62 | 90 | | |
63 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
64 | 99 | | |
65 | 100 | | |
66 | 101 | | |
67 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
68 | 107 | | |
69 | 108 | | |
70 | | - | |
| 109 | + | |
71 | 110 | | |
72 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
73 | 115 | | |
74 | 116 | | |
75 | 117 | | |
76 | | - | |
| 118 | + | |
77 | 119 | | |
78 | 120 | | |
79 | 121 | | |
80 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
81 | 127 | | |
82 | 128 | | |
83 | | - | |
| 129 | + | |
84 | 130 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
89 | 171 | | |
90 | 172 | | |
91 | 173 | | |
92 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
93 | 211 | | |
| 212 | + | |
94 | 213 | | |
95 | 214 | | |
96 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
97 | 220 | | |
98 | 221 | | |
99 | 222 | | |
| |||
108 | 231 | | |
109 | 232 | | |
110 | 233 | | |
111 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
112 | 238 | | |
113 | 239 | | |
114 | 240 | | |
115 | 241 | | |
116 | | - | |
| 242 | + | |
117 | 243 | | |
118 | 244 | | |
119 | 245 | | |
120 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
121 | 251 | | |
122 | 252 | | |
123 | | - | |
| 253 | + | |
124 | 254 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 255 | + | |
129 | 256 | | |
130 | 257 | | |
131 | 258 | | |
| |||
138 | 265 | | |
139 | 266 | | |
140 | 267 | | |
141 | | - | |
| 268 | + | |
142 | 269 | | |
143 | 270 | | |
144 | 271 | | |
145 | 272 | | |
146 | 273 | | |
147 | 274 | | |
148 | 275 | | |
149 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
150 | 281 | | |
151 | 282 | | |
152 | 283 | | |
| |||
0 commit comments