Commit 002515b
authored
fix(blink): synchronize first-paint styles before UICommand flush (#827)
## Summary
Fixes a Blink-first-paint “unstyled/incorrect style” window by deferring
UICommand package flushing until a synchronous style update has run for
the newly-mounted visual subtree.
## Problem
When the Blink CSS engine is enabled, DOM mutations can enqueue/flush
UICommand packages before Blink has performed the first
`Document::UpdateStyleForThisDocument()`. This can lead to:
- an unstyled first frame (style commands arrive in a later batch)
- `getComputedStyle()` returning incorrect defaults during early mount
- RouterLink (hybrid router) subpage mounts being especially prone to
the issue
## Solution
- Add a “first-paint style sync” barrier on `ExecutingContext`:
- `needs_first_paint_style_sync_` gates UICommand package emission
- `first_paint_committed_` prevents re-gating the initial document paint
- Arm the barrier on structural DOM insertions:
- `ContainerNode::{AppendChildCommon,InsertBeforeCommon}` call
`ExecutingContext::MaybeBeginFirstPaintStyleSync(...)`
- Special-case RouterLink:
- do not block insertion of the RouterLink container into `<body>`
(avoids hybrid-router deadlock)
- re-arm when the RouterLink subtree (route contents) mounts its first
child
- Ensure the barrier clears deterministically:
- `SharedUICommand::AddCommand` calls `MaybeUpdateStyleForFirstPaint()`
on `kFinishRecordingCommand` to force a synchronous style update when
required
- `Document::UpdateStyleForThisDocument()` calls
`MaybeCommitFirstPaintStyleSync()` after updating styles to finalize the
barrier state
- Defer UICommand packages while the barrier is active:
- `UICommandPackageRingBuffer::PushPackage()` diverts packages into a
deferred queue when gated
- `FlushDeferredPackages()` pushes deferred packages once the barrier is
cleared
- `Reset/Clear` updated to account for deferred packages and lock
ordering
## Tests
- Bridge unit test:
`bridge/foundation/blink_first_paint_style_sync_test.cc`
- Verifies style commands (`kClearStyle`, `kSetStyleById`) appear in the
first flushed batch.
- Integration test:
`integration_tests/specs/cssom/first_paint_barrier_sync_flush.ts`
- Verifies `getComputedStyle()` is unblocked and returns expected values
during RouterLink subtree mount.
- Stabilize Blob constructor spec by waiting for a frame before
`toBlob()`.
## How to test
- `node scripts/run_bridge_unit_test.js`
- `cd integration_tests && npm run integration`
## Notes / Risk
- Changes only take effect when the Blink engine is enabled.
- RouterLink handling is explicitly designed to avoid blocking
hybrid-router navigation while still gating the first painted subtree.File tree
12 files changed
+238
-6
lines changed- bridge
- core
- dom
- foundation
- test
- integration_tests/specs
- blob
- cssom
- webf/example/lib
12 files changed
+238
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
723 | 723 | | |
724 | 724 | | |
725 | 725 | | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
726 | 730 | | |
727 | 731 | | |
728 | 732 | | |
| |||
744 | 748 | | |
745 | 749 | | |
746 | 750 | | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
747 | 756 | | |
748 | 757 | | |
749 | 758 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
| 687 | + | |
687 | 688 | | |
688 | 689 | | |
689 | 690 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
827 | 828 | | |
828 | 829 | | |
829 | 830 | | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
830 | 835 | | |
831 | 836 | | |
832 | 837 | | |
833 | 838 | | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
834 | 889 | | |
835 | 890 | | |
836 | 891 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| |||
214 | 216 | | |
215 | 217 | | |
216 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
217 | 223 | | |
218 | 224 | | |
219 | 225 | | |
| |||
272 | 278 | | |
273 | 279 | | |
274 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
275 | 285 | | |
276 | 286 | | |
277 | 287 | | |
| |||
323 | 333 | | |
324 | 334 | | |
325 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
326 | 342 | | |
327 | 343 | | |
328 | 344 | | |
| |||
335 | 351 | | |
336 | 352 | | |
337 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
338 | 358 | | |
339 | 359 | | |
340 | 360 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
| |||
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
55 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
56 | 65 | | |
57 | 66 | | |
58 | 67 | | |
| |||
143 | 152 | | |
144 | 153 | | |
145 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
146 | 158 | | |
147 | 159 | | |
148 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
300 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
301 | 326 | | |
302 | 327 | | |
303 | 328 | | |
| |||
357 | 382 | | |
358 | 383 | | |
359 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
360 | 392 | | |
361 | 393 | | |
362 | 394 | | |
| |||
372 | 404 | | |
373 | 405 | | |
374 | 406 | | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
375 | 412 | | |
376 | 413 | | |
377 | 414 | | |
| |||
381 | 418 | | |
382 | 419 | | |
383 | 420 | | |
384 | | - | |
385 | | - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
386 | 425 | | |
387 | | - | |
388 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
389 | 435 | | |
390 | 436 | | |
391 | 437 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
111 | 115 | | |
112 | 116 | | |
113 | 117 | | |
| |||
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
142 | 150 | | |
143 | 151 | | |
144 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
0 commit comments