From 7ead24a138ce3a1d9b46bc7471d2689010d69777 Mon Sep 17 00:00:00 2001 From: Mukilan Thiyagarajan Date: Fri, 2 Jun 2023 20:34:51 +0530 Subject: [PATCH] Clear PositioningContext for speculative layouts `try_layout` is used for laying out absolutely positioned descendants multiple times when min/max-{width, height} properties are set. When the same PositioningContext instance is used between successive attempts without clearing the accumulated descendants, we will generate multiple fragments which reference the same box, which then will lead to a double borrow error when layout is performed in parallel. Signed-off-by: Mukilan Thiyagarajan --- components/layout_2020/positioned.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/components/layout_2020/positioned.rs b/components/layout_2020/positioned.rs index 37f2a0fb321..62907adba92 100644 --- a/components/layout_2020/positioned.rs +++ b/components/layout_2020/positioned.rs @@ -379,6 +379,14 @@ impl PositioningContext { ) } } + + pub(crate) fn clear(&mut self) { + self.for_nearest_containing_block_for_all_descendants + .clear(); + self.for_nearest_positioned_ancestor + .as_mut() + .map(|v| v.clear()); + } } impl HoistedAbsolutelyPositionedBox { @@ -563,6 +571,13 @@ impl HoistedAbsolutelyPositionedBox { "Mixed writing modes are not supported yet" ); let dummy_tree_rank = 0; + + // Clear the context since we will lay out the same descendants + // more than once. Otherwise, absolute descendants will create + // multiple fragments which could later lead to double-borrow + // errors. + positioning_context.clear(); + let independent_layout = non_replaced.layout( layout_context, &mut positioning_context,