fix(layout): guard the default tab-stop grid against a non-positive interval - #3947
leonidkuznetsov18 wants to merge 1 commit into
Conversation
…nterval A DOCX whose word/settings.xml carries <w:defaultTabStop w:val="0"/> froze the main thread forever: computeTabStops generates the automatic tab-stop grid with `pos += defaultTabInterval` toward a fixed limit, so an interval of 0 (or a negative one) never advances and the loop never terminates. onReady/onException never fire and the page pegs the CPU until the tab is killed. The grid is pre-computed for every measured paragraph, so any document with text content triggers it — no tab characters required. Word writes defaultTabStop 0 when a user sets the default tab interval to 0, opens such documents fine, and simply generates no automatic tab stops. Do the same: skip the default grid for a non-positive (or non-finite) interval, keeping explicit stops and the implicit indent-driven stops intact. Mirrors the existing guard in word-layout's computeTabStops. Fixes superdoc#3944 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
Thanks, Leonid, for the clear investigation and regression tests. The zero default tab-stop hang has been addressed in V2 and shipped in 2.13.0. We also verified that the zero-value fixture opens and remains responsive in 2.14.0. The shipped fix falls back to the standard tab interval, so we’re closing this PR as superseded for the reported hang. Please upgrade to 2.13.0 or later. |
What
A DOCX whose
word/settings.xmlcarries<w:defaultTabStop w:val="0"/>froze the main thread forever:onReady/onExceptionnever fired and the tab pegged the CPU until killed (#3944).computeTabStops(packages/layout-engine/contracts/src/engines/tabs.ts) generates the automatic tab-stop grid withpos += defaultTabIntervaltoward a fixed limit, so an interval of0(or a negative one) never advances and the loop never terminates. BothbuildTabStopsPxcallers (measuring/domandlayout-bridge/remeasure) pass the document value throughtabIntervalTwips ?? DEFAULT_TAB_INTERVAL_TWIPS, and??doesn't catch0. The grid is pre-computed for every measured paragraph, which is why any document with text content triggers it — no tab characters required (an empty<w:p/>escapes via the simple-empty-paragraph fast path, matching the repro matrix in the issue).Fix
Skip the default grid for a non-positive (or non-finite) interval, keeping explicit stops and the implicit indent-driven stops intact. Word writes
defaultTabStop0 when a user sets the default tab interval to 0, opens such documents fine, and simply generates no automatic tab stops — so "no grid" is the Word-faithful behavior, and it mirrors the existing guard inword-layout's owncomputeTabStops(packages/word-layout/src/tab-layout.ts).Guarding this single choke point covers both callers; it is the only
+= intervalloop over the document value in the layout engine.Testing
tabs.test.tsfor interval0(no default grid, terminates) and a negative interval (explicit stops preserved, no default grid). Without the guard the first test hangs the runner — verified by stashing the fix: the suite ran into a 3-minute wall timeout exactly as described in the issue.packages/layout-engine/contracts: 492/492 pass.measuring/dom529/529,layout-bridge1653/1653 pass.Fixes #3944