fix: navbar font mismatch and overlap before Bootstrap loads
What does this PR aim to accomplish?:
After #1036, the monochrome navbar still renders Chinese text in different fonts on /web and classic pages. Both pages load Source Serif 4 and have identical computed font-family, but that font contains no Chinese glyphs. Classic declares lang=en while /web declares lang=zh-CN. On macOS Chromium, the browser picks PingFang SC for classic and Songti SC for /web. Switching the live /web document language to en also changes its rendered Chinese navbar font to PingFang SC.
A second reproducible failure affects generic page layouts when the Bootstrap resource cache is empty and its CDN fallback is delayed or fails. NavbarStyler sets position:fixed but relies on Bootstrap's .fixed-top for top:0. With top:auto, inserting the body spacer pushes the navbar down with the page, where it covers the first content instead of anchoring to the viewport. An offline layout probe reproduces overlap in all 24 width/skin/theme/menu combinations per version on both stable and pre-fix dev.
Related to issue #1038. Its reported all-page overlap remains unconfirmed in the reporter's browser because it contains no reproduction steps. This PR fixes the demonstrated missing-CSS condition and does not claim that it is the confirmed cause of that report.
How does this PR accomplish the above?:
Give the monochrome navbar and its links one explicit font stack, preserving the existing Latin serif fonts and adding PingFang SC, Microsoft YaHei and Noto Sans CJK SC before the generic fallback. The brand, user dropdown and dropdown items inherit that navbar stack. Body typography remains unchanged.
Pin the navbar top offset directly in NavbarStyler, so viewport anchoring works before Bootstrap is available. Preserve and restore its original inline top value and priority during teardown.
Validation:
- The new offline Chromium regression compares actual rendered glyph fonts through CSS.getPlatformFontsForNode for the brand, navigation links, username span and dropdown items under both document languages. It fails on the pre-fix code (Songti SC versus PingFang SC) and passes with this change.
- The regression bundles the unmodified 20 KB Latin subset of the existing Source Serif 4 font with its OFL license. An unloaded font or local substitute does not reproduce the bug; the test asserts the webfont loaded. No new dependency was added.
- A new browser regression fails before the positioning fix and passes after it, checking mobile/desktop widths and both skins without Bootstrap, after its positioning CSS arrives, and after teardown. It also checks restoration of an existing important top offset.
- The wider offline layout probe has zero overlaps with the fixed code in all 24 combinations, both with and without Bootstrap. Stable code remains the failing control without Bootstrap.
- All 20 npm tests pass using the installed Chromium. Userscript syntax and diff whitespace checks pass.
- A separate automated probe injects the shared initialization and actual navbar conversion code into the public /web/contest and classic home pages. Both now render Chinese navbar glyphs with PingFang SC, Latin glyphs with Source Serif 4, and matching font size, weight and spacing. This is not an end-to-end test of an installed userscript or authenticated account.
Please verify this with the installed userscript in both UIs before merging. The final checklist is unchecked because template item 11 requires human verification; the earlier PR was merged without that check.
By submitting this pull request, I confirm the following:
- I have read and understood the contributor's guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
- I have commented on my proposed changes within the code.
- I have tested my changes.
- I am willing to help maintain this change if there are issues with it later.
- It is compatible with the GNU General Public License v3.0
- I have squashed any insignificant commits. (
git rebase) - I have checked that another pull request for this purpose does not exist.
- I have considered and confirmed that this submission will be valuable to others.
- I accept that this submission may not be used, and the pull request can be closed at the will of the maintainer.
- I give this submission freely and claim no ownership to its content.
- I have verified that my changes work correctly in both the new UI and the old/classic UI.
- I have read the above and my PR is ready for review. Check this box to confirm
Summary by Sourcery
Fix monochrome navbar font consistency and prevent content overlap while Bootstrap styles are unavailable.
Bug Fixes:
- Standardize Chinese glyph rendering across legacy and web monochrome navigation bars by adding an explicit shared font fallback stack.
- Prevent the navigation bar from overlapping page content when Bootstrap styles are unavailable or delayed by enforcing viewport top anchoring.
Enhancements:
- Preserve and restore existing inline navigation top offsets, including priority, when navigation styling is removed.
Build:
- Bump the userscript and package versions to 3.8.2.
Tests:
- Add browser regressions covering language-independent navbar glyph fonts and layout behavior before and after Bootstrap loading.
Chores:
- Add the Source Serif 4 fixture and its licensing information for offline font rendering tests.
- Record the 3.8.2 update metadata.