fix(client): correct scrollbar width range check by rajanpanth · Pull Request #69839 · freeCodeCamp/freeCodeCamp · GitHub
Skip to content

fix(client): correct scrollbar width range check - #69839

Open
rajanpanth wants to merge 1 commit into
freeCodeCamp:mainfrom
rajanpanth:fix/scrollbar-width-range-check
Open

fix(client): correct scrollbar width range check#69839
rajanpanth wants to merge 1 commit into
freeCodeCamp:mainfrom
rajanpanth:fix/scrollbar-width-range-check

Conversation

@rajanpanth

@rajanpanth rajanpanth commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Checklist:

What

getScrollbarWidth in client/src/utils/scrollbar-width.ts is meant to sanitize the persisted Monaco scrollbar width to the 5-25 range, but the guard uses ||:

return storedWidth >= 5 || storedWidth <= 25 ? storedWidth : 5;

Every number is either >= 5 or <= 25, so the condition is a tautology and the fallback is only reachable for undefined/NaN. A corrupted or hand-edited monacoScrollbarWidth in localStorage (0, 100, -3) is applied verbatim to the editor: editor.tsx feeds this value into Monaco's verticalScrollbarSize/arrowSize and a width calculation in four places.

The condition wants &&. One character, plus a unit test file so the range check cannot regress silently again (the bug shipped with the original feature PR #49975 and was never caught because the file had no tests).

Verification

scrollbar-width.test.ts covers in-range passthrough, both out-of-range sides, and the unset case, with store mocked. All 4 pass with the fix. Reverting only scrollbar-width.ts fails exactly the two out-of-range tests (expected +0 to be 5, expected 100 to be 5), so the tests isolate the change.

Opened directly without an issue per the contributing FAQ guidance for small self-contained fixes; happy to open one if preferred.

getScrollbarWidth guards the stored Monaco scrollbar width with
storedWidth >= 5 || storedWidth <= 25, which is true for every number,
so out-of-range values from local storage (e.g. 0 or 100) are applied
to the editor instead of the fallback. Use && so only widths in the
5-25 range pass, and add unit tests.
@rajanpanth
rajanpanth requested review from a team as code owners September 2, 2026 11:28
@github-actions github-actions Bot added platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. deprioritized PR reviews are deprioritized; lacks productive input and ignores codebase best practices. labels Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot removed the deprioritized PR reviews are deprioritized; lacks productive input and ignores codebase best practices. label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: learn UI side of the client application that needs familiarity with React, Gatsby etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant