Commit c3d1c06
authored
feat: eagerly load ExtendedClientDetails during UI initialization (#22719)
* feat: eagerly load ExtendedClientDetails during UI initialization
Browser details (ExtendedClientDetails) are now automatically fetched
during UI initialization and available immediately in the UI constructor,
eliminating the need for asynchronous callbacks in most cases.
API changes:
- Page.getExtendedClientDetails(): Now always returns a non-null instance
(creates placeholder with default values if not yet fetched). Browser
details are automatically populated during normal UI initialization.
- ExtendedClientDetails.refresh(Consumer): New method to refresh cached
browser details with fresh values from the browser. Callback is invoked
when refresh completes.
- Page.retrieveExtendedClientDetails(ExtendedClientDetailsReceiver):
Deprecated. Use getExtendedClientDetails() to access cached details, or
ExtendedClientDetails.refresh() to update them.
Migration guide:
Before:
page.retrieveExtendedClientDetails(details -> {
int width = details.getScreenWidth();
});
After:
ExtendedClientDetails details = page.getExtendedClientDetails();
int width = details.getScreenWidth(); // Available immediately
// Or refresh if needed:
details.refresh(updated -> {
int width = updated.getScreenWidth();
});
Benefits:
- No null checks needed when accessing browser details
- Browser details available immediately in UI constructor/onAttach
- Simpler synchronous API for common use cases
- Full backward compatibility maintained
* Make browser details collection available before init request completes
The browser details collection function getBrowserDetailsParameters was
previously defined in FlowBootstrap.js, which was loaded after the init
request. This caused the function to be undefined when Flow.ts tried to
collect browser details to send with the ?v-r=init request.
This change moves the browser details collection logic from
FlowBootstrap.js into Flow.ts as a private method collectBrowserDetails(),
and registers it as window.Vaadin.Flow.getBrowserDetailsParameters in the
Flow constructor. This ensures the function is available when needed
during the init request, while maintaining backward compatibility for code
that calls the function via the global window object.
The TypeScript implementation uses ($wnd as any) casts to access window
properties like screen, document, navigator, etc., since the $wnd type
doesn't include all browser DOM APIs. Values are stringified before
returning to match the original JavaScript implementation.
Also adds integration test to verify browser details are available
immediately on page load without user interaction.
* Make getExtendedClientDetails() always return non-null
Browser details are now sent eagerly with the init request, but
getExtendedClientDetails() could still return null before the data
arrives. This changes the API to always return a non-null instance,
using a placeholder with default values (screenWidth = -1, windowName
= null) until actual browser details are available.
For PreserveOnRefresh functionality, the code now checks if windowName
is null rather than checking if the entire ExtendedClientDetails object
is null. This is necessary because:
- Screen dimensions are always sent with the init request
- But window.name may be empty/undefined in new browser windows
- This causes windowName = null even when other details are present
- Different windows with windowName = null would incorrectly share
cached components
Changes:
- Made ExtendedClientDetails constructor public (marked as internal-only)
- UIInternals.getExtendedClientDetails() creates placeholder if null
- Page.getExtendedClientDetails() simplified to delegate to UIInternals
- Page.retrieveExtendedClientDetails() checks screenWidth == -1
- AbstractNavigationStateRenderer: Changed 3 locations to check
windowName == null instead of details == null
- WebComponentUI: Changed to check windowName == null
This fixes PreserveOnRefreshIT.refreshInDifferentWindow_componentIsRecreated
test failure where components were incorrectly preserved across different
browser windows due to cache key collisions.
* Tweak details1 parent 26b8df0 commit c3d1c06
File tree
14 files changed
+404
-281
lines changed- flow-client/src/main/frontend
- flow-server/src
- main/java/com/vaadin/flow
- component
- internal
- page
- webcomponent
- router/internal
- server/communication
- test/java/com/vaadin
- flow/component/page
- tests/util
- flow-tests/test-root-context/src
- main/java/com/vaadin/flow
- uitest/ui
- test/java/com/vaadin/flow/uitest/ui
14 files changed
+404
-281
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
| |||
425 | 427 | | |
426 | 428 | | |
427 | 429 | | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
428 | 437 | | |
429 | 438 | | |
430 | | - | |
| 439 | + | |
431 | 440 | | |
432 | 441 | | |
433 | 442 | | |
| |||
452 | 461 | | |
453 | 462 | | |
454 | 463 | | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
455 | 553 | | |
456 | 554 | | |
457 | 555 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 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 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | 186 | | |
273 | 187 | | |
274 | 188 | | |
| |||
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1347 | 1347 | | |
1348 | 1348 | | |
1349 | 1349 | | |
1350 | | - | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
1351 | 1354 | | |
1352 | | - | |
1353 | | - | |
| 1355 | + | |
1354 | 1356 | | |
1355 | 1357 | | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
1356 | 1364 | | |
1357 | 1365 | | |
1358 | 1366 | | |
| |||
Lines changed: 96 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
26 | 34 | | |
27 | 35 | | |
28 | | - | |
29 | | - | |
30 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
31 | 41 | | |
32 | 42 | | |
33 | 43 | | |
34 | 44 | | |
35 | 45 | | |
| 46 | + | |
36 | 47 | | |
37 | 48 | | |
38 | 49 | | |
| |||
54 | 65 | | |
55 | 66 | | |
56 | 67 | | |
| 68 | + | |
| 69 | + | |
57 | 70 | | |
58 | 71 | | |
59 | 72 | | |
| |||
88 | 101 | | |
89 | 102 | | |
90 | 103 | | |
91 | | - | |
| 104 | + | |
92 | 105 | | |
93 | 106 | | |
94 | 107 | | |
95 | 108 | | |
96 | 109 | | |
97 | 110 | | |
| 111 | + | |
98 | 112 | | |
99 | 113 | | |
100 | 114 | | |
| |||
382 | 396 | | |
383 | 397 | | |
384 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
385 | 477 | | |
0 commit comments