Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid while cycle in computeMaxFontSize for big Number run forever when css !important rule applied #20067

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,20 @@ function decreaseSizeUntil(
): number {
let size = startSize;
let dimension = computeDimension(size);

while (!condition(dimension)) {
size -= 1;

// Here if the size goes below zero most likely is because it
// has additional style applied in which case we assume the user
// knows what it's doing and we just let them use that.
// Visually it works, although it could have another
// check in place.

if (size < 0) {
size = startSize;
break;
}
dimension = computeDimension(size);
}

Expand All @@ -43,7 +55,6 @@ export default function computeMaxFontSize(
},
) {
const { idealFontSize, maxWidth, maxHeight, style, ...rest } = input;

let size: number;
if (idealFontSize !== undefined && idealFontSize !== null) {
size = idealFontSize;
Expand All @@ -66,15 +77,15 @@ export default function computeMaxFontSize(
size = decreaseSizeUntil(
size,
computeDimension,
dim => dim.width <= maxWidth,
dim => dim.width > 0 && dim.width <= maxWidth,
);
}

if (maxHeight !== undefined && maxHeight !== null) {
size = decreaseSizeUntil(
size,
computeDimension,
dim => dim.height <= maxHeight,
dim => dim.height > 0 && dim.height <= maxHeight,
);
}

Expand Down