Repository navigation
fix: navbar listener leaks, download overlap, and web fonts #1036
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c1b6d4b
fix: reuse navbar styler and clean up resize listeners
boomzero d175414
3.8.1
github-actions[bot] 0e3cbb5
Update version info to 3.8.1
github-actions[bot] 519b281
fix: restore navbar styling and remove owned artifacts on teardown
boomzero 965f08a
Update time and description of 3.8.1
github-actions[bot] 51dc11e
Update time and description of 3.8.1
github-actions[bot] 56c4989
Update time and description of 3.8.1
github-actions[bot] f21d58c
Update time and description of 3.8.1
github-actions[bot] ac477fe
fix: keep downloads out of the navbar spacer
boomzero 4654237
Update time and description of 3.8.1
github-actions[bot] 3fcc576
Update time and description of 3.8.1
github-actions[bot] a64b24a
fix: load the same monochrome fonts on web and classic pages
boomzero 8381325
Update time and description of 3.8.1
github-actions[bot] 8758133
Update time and description of 3.8.1
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| const test = require('node:test'); | ||
| const assert = require('node:assert/strict'); | ||
| const fs = require('node:fs'); | ||
| const path = require('node:path'); | ||
| const {chromium} = require('playwright'); | ||
|
|
||
| const source = fs.readFileSync(path.join(__dirname, '../XMOJ.user.js'), 'utf8'); | ||
|
|
||
| test('navbar refreshes keep one resize listener and release replaced navbars', {timeout: 60000}, async () => { | ||
| const start = 'let navbarStyler = null;'; | ||
| const end = '// Wrapped in an async IIFE'; | ||
| for (const marker of [start, end]) { | ||
| assert.equal(source.split(marker).length - 1, 1, 'expected one navbar extraction marker: ' + marker); | ||
| } | ||
| const navbarSource = source.slice(source.indexOf(start), source.indexOf(end)); | ||
| const browser = await chromium.launch({executablePath: process.env.XMOJ_CHROMIUM || undefined}); | ||
| const page = await browser.newPage(); | ||
| const errors = []; | ||
| page.on('pageerror', error => errors.push(error.message)); | ||
| page.on('console', message => { if (message.type() === 'error') errors.push(message.text()); }); | ||
| try { | ||
| await page.setContent('<nav class="navbar navbar-expand-lg bg-body-tertiary" style="height:48px">Classic navbar</nav>'); | ||
| await page.evaluate(() => { | ||
| window.topBarEnabled = true; | ||
| window.UtilityEnabled = name => name === 'NewTopBar' && window.topBarEnabled; | ||
| window.resizeListeners = new Set(); | ||
| const add = window.addEventListener; | ||
| const remove = window.removeEventListener; | ||
| window.addEventListener = function(type, listener, options) { | ||
| if (type === 'resize') window.resizeListeners.add(listener); | ||
| return add.call(this, type, listener, options); | ||
| }; | ||
| window.removeEventListener = function(type, listener, options) { | ||
| if (type === 'resize') window.resizeListeners.delete(listener); | ||
| return remove.call(this, type, listener, options); | ||
| }; | ||
| }); | ||
| await page.addScriptTag({content: navbarSource}); | ||
| const result = await page.evaluate(() => { | ||
| const counts = []; | ||
| // Simulate sustained polling without waiting for either UI's timer. | ||
| for (let i = 0; i < 2000; i++) UpdateNavbarStyler(); | ||
| counts.push(window.resizeListeners.size); | ||
| const originalListener = [...window.resizeListeners][0]; | ||
| const firstNavbar = document.querySelector('nav'); | ||
| firstNavbar.outerHTML = '<nav class="navbar navbar-expand-lg bg-body-tertiary" style="height:80px">Vue replacement</nav>'; | ||
| window.dispatchEvent(new Event('resize')); | ||
|
boomzero marked this conversation as resolved.
Resolved
|
||
| for (let i = 0; i < 2000; i++) UpdateNavbarStyler(); | ||
| counts.push(window.resizeListeners.size); | ||
| const removedOldListener = !window.resizeListeners.has(originalListener); | ||
| const navbar = document.querySelector('nav'); | ||
| navbar.style.height = '96px'; | ||
| window.dispatchEvent(new Event('resize')); | ||
| const overlayHeightAfterResize = document.getElementById('blur-overlay').style.height; | ||
| UpdateNavbarStyler(); | ||
| const spacerHeight = document.getElementById('navbar-spacer').style.height; | ||
| const overlayCount = document.querySelectorAll('#blur-overlay').length; | ||
| const spacerCount = document.querySelectorAll('#navbar-spacer').length; | ||
| window.topBarEnabled = false; | ||
| UpdateNavbarStyler(); | ||
| counts.push(window.resizeListeners.size); | ||
| window.topBarEnabled = true; | ||
| UpdateNavbarStyler(); | ||
| counts.push(window.resizeListeners.size); | ||
| navbar.remove(); | ||
| window.dispatchEvent(new Event('resize')); | ||
| UpdateNavbarStyler(); | ||
| counts.push(window.resizeListeners.size); | ||
| const retainedNavbar = navbarStyler !== null; | ||
| return {counts, removedOldListener, overlayHeightAfterResize, spacerHeight, overlayCount, spacerCount, retainedNavbar}; | ||
| }); | ||
| assert.deepEqual(result.counts, [1, 1, 0, 1, 0]); | ||
| assert.equal(result.removedOldListener, true); | ||
| assert.equal(result.overlayHeightAfterResize, '96px'); | ||
| assert.equal(result.spacerHeight, '120px'); | ||
| assert.equal(result.overlayCount, 1); | ||
| assert.equal(result.spacerCount, 1); | ||
| assert.equal(result.retainedNavbar, false); | ||
| assert.deepEqual(errors, []); | ||
| } finally { | ||
| await browser.close(); | ||
| } | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.