bigskysoftware / bigskysoftware/htmx

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

Open
#3,726 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

Version 2.0.7.

### Steps

1) The web page has a `title` tag in `head` block.
1) 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(

... (helper data)...
)

function helper (data)
title = f(data)
return fragment(...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:

```html




Foo

```

### Workaround

My current workaround is to use OOB swapping, i.e. replacing all `title` tags (including in `head`) with `...`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.