Skip to content

Commit

Permalink
wrong cbBlockStart -> inf loop in findLinePosition
Browse files Browse the repository at this point in the history
  • Loading branch information
chearon committed Apr 18, 2024
1 parent 531d58a commit 28e9150
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/layout-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,9 +1163,10 @@ function layoutContribution(box: BlockContainer, ctx: LayoutContext, mode: 'min-

if (box.isBfcRoot()) cctx.bfc = new BlockFormattingContext(mode === 'min-content' ? 0 : Infinity);

ctx.bfc.boxStart(box, cctx);

if (box.isBlockContainerOfInlines()) {
const [ifc] = box.children;
box.doTextLayout(cctx);
for (const line of ifc.paragraph.lineboxes) {
intrinsicSize = Math.max(intrinsicSize, line.width);
}
Expand All @@ -1190,6 +1191,8 @@ function layoutContribution(box: BlockContainer, ctx: LayoutContext, mode: 'min-
}
}

ctx.bfc.boxEnd(box);

const marginLineLeft = box.style.getMarginLineLeft(box);
const marginLineRight = box.style.getMarginLineRight(box);
const borderLineLeftWidth = box.style.getBorderLineLeftWidth(box);
Expand Down Expand Up @@ -1219,13 +1222,15 @@ export function layoutFloatBox(box: BlockContainer, ctx: LayoutContext) {
let inlineSize = box.getDefiniteInlineSize();

if (inlineSize === undefined) {
const cctx = {...ctx};
cctx.bfc = new BlockFormattingContext(0); // Not used, but children call it
if (ctx.mode === 'min-content') {
inlineSize = layoutContribution(box, ctx, 'min-content');
inlineSize = layoutContribution(box, cctx, 'min-content');
} else if (ctx.mode === 'max-content') {
inlineSize = layoutContribution(box, ctx, 'max-content');
inlineSize = layoutContribution(box, cctx, 'max-content');
} else {
const minContent = layoutContribution(box, ctx, 'min-content');
const maxContent = layoutContribution(box, ctx, 'max-content');
const minContent = layoutContribution(box, cctx, 'min-content');
const maxContent = layoutContribution(box, cctx, 'max-content');
const availableSpace = box.containingBlock.inlineSize;
inlineSize = Math.max(minContent, Math.min(maxContent, availableSpace));
}
Expand Down
17 changes: 17 additions & 0 deletions test/flow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,23 @@ describe('Flow', function () {
expect(this.get('#t').contentArea.x).to.equal(10);
});

it('doesn\'t infinite loop in a specific case', function () {
// The float lazily-creates the FloatContext which can only search the
// block direction at or after the block offset it's created at. The
// intrinsics pass had wrong BFC offsets that got passed to the
// FloatContext causing infinite looping in findLinePosition in this case.
// (this happened in the min-content phase)
this.layout(`
<div style="float: left;">
First, there was this guy.
<div style="float: right;">
His name was
</div>
<div>Baxter Fennel</div>
</div>
`);
});

// §9.5.1
// some of the rules don't really make sense to test alone - they all work
// together to create a single concept - but most of them do, and it's a way
Expand Down

0 comments on commit 28e9150

Please sign in to comment.