bigskysoftware/htmx

Page title not restored correctly after back button in Firefox

ainz-95 opened this issue · 1 comments

This seems to happen in Firefox (129.0) but not in Chrome (127.0) with version 2.0.2, where the user clicks back button and the page title is not correctly restored. See reproduction link below:

https://stackblitz.com/edit/htmx-firefox-back-title-issue?file=index.html

  1. Click Open Preview in New Tab
  2. Page title is Home Page
  3. Navigate via Click Me!
  4. Page title is Hello Page
  5. Navigate via browser back button
  6. Page title is still Hello Page

reproduced this in firefox. debugging it and I can see that in chrome the title is cached by chrome itself for back history requests and the htmx code does not set the title because it uses the fragment data to get the title but it doesn't store the title in fragment so it just leaves it up to the browser to set title. The title is stored in the cache though so just changing one line from fragment.title to cached.title fixed it for me in firefox.

  function restoreHistory(path) {
    saveCurrentPageToHistory()
    path = path || location.pathname + location.search
    const cached = getCachedHistory(path)
    if (cached) {
      const fragment = makeFragment(cached.content)
      const historyElement = getHistoryElement()
      const settleInfo = makeSettleInfo(historyElement)
      handleTitle(cached.title) // changed this one line from fragment.title