Skip to content

Fix baseWidth fallback cascade in export width measurement#17

Merged
byemaxx merged 2 commits intostagingfrom
copilot/sub-pr-16
Jan 7, 2026
Merged

Fix baseWidth fallback cascade in export width measurement#17
byemaxx merged 2 commits intostagingfrom
copilot/sub-pr-16

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 7, 2026

Addresses feedback on #16 regarding flawed fallback logic that prevented rect.width from being evaluated when intrinsic width measurements failed.

Problem

The existing fallback logic applied the minimum value too early, making the conditional check unreachable:

baseWidth = Math.max(el.scrollWidth || 0, el.offsetWidth || 0, 1);
if (!baseWidth || !Number.isFinite(baseWidth)) baseWidth = Math.max(rect.width || 0, 1);

Since Math.max(..., 1) guarantees baseWidth >= 1, the condition !baseWidth is never true, and rect.width is never checked.

Solution

Restructured to cascade through measurements before applying the minimum:

// Try intrinsic measurements first
baseWidth = Math.max(el.scrollWidth || 0, el.offsetWidth || 0);
// Fall back to bounding rect if intrinsic measurements fail
if (!baseWidth || !Number.isFinite(baseWidth)) {
  baseWidth = rect.width || 0;
}
// Apply minimum only after all measurements attempted
baseWidth = Math.max(baseWidth, 1);

This ensures all available width sources are evaluated before defaulting to the hardcoded minimum.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: byemaxx <44231502+byemaxx@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix matrix layout and export cropping based on feedback Fix baseWidth fallback cascade in export width measurement Jan 7, 2026
Copilot AI requested a review from byemaxx January 7, 2026 00:21
@byemaxx byemaxx marked this pull request as ready for review January 7, 2026 00:24
@byemaxx byemaxx merged commit 9048127 into staging Jan 7, 2026
@byemaxx byemaxx deleted the copilot/sub-pr-16 branch January 7, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants