Closed tomtseng closed 6 months ago
Name | Link |
---|---|
Latest commit | 803434d92f384b1ee3fdb95d957e29d833bf109f |
Latest deploy log | https://app.netlify.com/sites/goattack/deploys/662af8a734c54600086a77e0 |
Deploy Preview | https://deploy-preview-100--goattack.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
Lighthouse |
1 paths audited Performance: 90 (no change from production) Accessibility: 95 (no change from production) Best Practices: 100 (no change from production) SEO: 85 (no change from production) PWA: - View the detailed breakdown and full score reports |
To edit notification comments on pull requests, go to your Netlify site configuration.
This PR fixes issues with the browser back button.
Bug 1: Navbar in Firefox.
Repro: In Firefox (but not in Chrome), go to goattack.far.ai, click on "Baseline Attacks" in the navbar, and click the browser back button. The URL changes, but unexpectedly, the page content does not go back to the home page.
Bug: I'm not sure why this only happens in Firefox, but here's what I think is happening in
App.svelte
to cause this issue:let windowLocationPathname = window.location.pathname;
that holds the current page path.$: currentPath
that determines the page contents. The variable indirectly depends on windowLocationPathname, so we expect changes in windowLocationPathname to propagate tocurrentPath
.NavBar.svelte
, when we click a link, we modifycurrentPath
in order to change the page contents. Clicking the link also does changewindow.location.pathname
, but this does NOT updatewindowLocationPathname
.popstate
handler that updateswindowLocationPathname = window.location.pathname
.windowLocationPathname
was never updated when we clicked a NavBar link, the value ofwindowLocationPathname
is the same before and after thepopstate
handler. Then no changes are propagated tocurrentPath
.Fix: Make the
popstate
handler directly updatecurrentPath
.Other fixes I considered:
windowLocationPathname
reactive ($: windowLocationPathname = window.location.pathname;
) doesn't workimport { page } from '$app/stores';
, and then you can get the current URL with$page.url.pathname
. But SvelteKit is a framework based on Svelte, not a drop-in library interoperates with existing Svelte apps. It might not be easy to convert our existing webapp to SvelteKit.svelte-router
has a hookuseLocation()
that gets the current path, but inApp.svelte
it just returnsundefined
. I think it only tracks the location withinsvelte-router
<Router>
components?Maybe there's an cleaner fix, I'm not familiar with Svelte
Bug 2: Table of contents (ToC)
Repro: Go to goattack.far.ai/transfer and alternately click on the two ToC entries a bunch of times to navigate between URL fragments
#leela
and#elf
. Now click the URL back button a few times. The expected browser history is[transfer#leela, transfer#elf, transfer#leela, transfer#elf, ...]
. But instead the history is[transfer#leela, transfer, transfer#elf, transfer, transfer#leela, transfer, transfer#elf, ...]
Fix: Just get rid of the
onClick
handler in the ToC that modifies the history withwindow.history.pushState()
. I'm not sure why thatonClick
handler existed.Testing
Tested the PR on Firefox and Chrome