Skip to content

title tag not at the top of the response does not update the existing tab title #3726

@metametadata

Description

@metametadata

Version 2.0.7.

Steps

  1. The web page has a title tag in head block.
  2. Perform an htmx swap where the response contains the title tag inside a div block (instead of being one of the "top" tags in the response).

Expected

The tab title is updated.

Actual

The tab title is not updated.

Why is this needed?

Because in my current code the response is constructed by calling several functions and it's most convenient and logical to set the title in one of them. Simplified pseudocode:

function handle-response (request) 
    data = prepare-data (request
    return page(<div class="container">... (helper data)...</div>)

function helper (data)
   title = f(data)
   return fragment(...<title>title</title> ...)

This doesn't demonstrate well why the title calculation has to be in helper, but let's not dive much into this. I think htmx could simply search for title in the whole response.

Notes

The window title is updated if the original page has no title in head. But this could be the built-in browser "autofixing" behavior and is unrelated to htmx code. E.g. the next html file will have title Foo in Firefox:

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
     <title>Foo</title>
  </body>
</html>

Workaround

My current workaround is to use OOB swapping, i.e. replacing all title tags (including in head) with <title hx-swap-oob="true" id="document-title">...</title>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions