Skip to content

Commit bf1243e

Browse files
committed
feat(dom, css): add MaybeCommitFirstPaintStyleSync to finalize first-paint style updates
- Introduced `ExecutingContext::MaybeCommitFirstPaintStyleSync` to clear first-paint style sync barriers after a synchronous style update. - Ensured deferred UI commands are flushed post-update for accurate `getComputedStyle()` results. - Updated `Document::UpdateStyle()` to call the new method. - Adjusted and normalized integration tests for first-paint barrier scenarios.
1 parent 3e62d27 commit bf1243e

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

bridge/core/dom/document.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ void Document::UpdateStyleForThisDocument() {
684684
style_engine.InvalidateEnvDependentStylesIfNeeded();
685685
UpdateStyleInvalidationIfNeeded();
686686
UpdateStyle();
687+
context->MaybeCommitFirstPaintStyleSync();
687688

688689
auto duration_ms =
689690
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time).count();

bridge/core/executing_context.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,15 @@ void ExecutingContext::MaybeUpdateStyleForFirstPaint() {
877877
first_paint_committed_ = true;
878878
}
879879

880+
void ExecutingContext::MaybeCommitFirstPaintStyleSync() {
881+
if (!enable_blink_engine_ || !needs_first_paint_style_sync_) {
882+
return;
883+
}
884+
885+
needs_first_paint_style_sync_ = false;
886+
first_paint_committed_ = true;
887+
}
888+
880889
void ExecutingContext::FlushUICommand(const BindingObject* self, uint32_t reason) {
881890
std::vector<NativeBindingObject*> deps;
882891
FlushUICommand(self, reason, deps);

bridge/core/executing_context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ class ExecutingContext {
216216
FORCE_INLINE bool isIdle() const { return is_idle_; }
217217
FORCE_INLINE void SetIsIdle(bool is_idle) { is_idle_ = is_idle; }
218218
FORCE_INLINE void MarkNeedsStyleUpdateInMicrotask() { is_needs_update_styles_in_microtask_ = true; }
219+
// If a "first-paint style sync" barrier is active, clear it after we've
220+
// performed a synchronous style update so deferred UICommand packages can be
221+
// flushed to Dart (e.g. for getComputedStyle()).
222+
void MaybeCommitFirstPaintStyleSync();
219223

220224
// Cached media/viewport values pushed from Dart (e.g., during resize). These
221225
// avoid synchronous GetBindingProperty calls (which may flush layout) during

integration_tests/specs/cssom/first_paint_barrier_sync_flush.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe('First-paint barrier: synchronous flush', () => {
2-
fit('unblocks getComputedStyle() during RouterLink subtree mount', () => {
2+
it('unblocks getComputedStyle() during RouterLink subtree mount', () => {
33
const style = document.createElement('style');
44
style.textContent = '.sync-flush-box { color: rgb(255, 0, 0); }';
55
document.head.appendChild(style);
@@ -26,4 +26,3 @@ describe('First-paint barrier: synchronous flush', () => {
2626
routerLink.remove();
2727
});
2828
});
29-

0 commit comments

Comments
 (0)