fix: preserve details open state across htmx swaps#918
Draft
inoovador wants to merge 1 commit intoNixOS:mainfrom
Draft
fix: preserve details open state across htmx swaps#918inoovador wants to merge 1 commit intoNixOS:mainfrom
inoovador wants to merge 1 commit intoNixOS:mainfrom
Conversation
fricklerhandwerk
requested changes
Mar 24, 2026
Collaborator
fricklerhandwerk
left a comment
There was a problem hiding this comment.
Needs tests :)
| // Preserve the open/closed state of <details> elements across htmx swaps. | ||
| // Without this, expanded "Ignored packages" or "Ignored maintainers" | ||
| // sections collapse every time an item is ignored or restored. | ||
| // See: https://github.com/NixOS/nix-security-tracker/issues/913 |
Collaborator
There was a problem hiding this comment.
Link to the author of that snippet and give proper credit
When ignoring or restoring items (packages/maintainers), htmx replaces the suggestion element, causing all <details> sections to revert to their default collapsed state. This is disruptive when working through multiple ignored items in a row. Add a small script that listens to htmx:beforeSwap to record which <details> elements (by ID) are currently open, then restores the open attribute on matching elements after htmx:afterSwap completes. Approach inspired by @kizmonavt (bigskysoftware/htmx#2195). Fixes NixOS#913
9727024 to
cf13c52
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
<details>sections (e.g. "Ignored packages", "Ignored maintainers") no longer collapse when ignoring or restoring itemshtmx.min.jsinbase.htmlthat saves theopenstate of<details>elements (by ID) before an htmx swap and restores it after the swap completeshtmx:beforeSwapandhtmx:afterSwapevents as suggested in htmx#2195How it works
htmx:beforeSwap, the script collects the IDs of all<details open>elements inside the swap targethtmx:afterSwap, it finds those elements by ID in the new content and sets theopenattribute backOnly
<details>elements with anidattribute are tracked, which currently covers the ignored packages and ignored maintainers sections — exactly the ones affected by this issue.Test plan
<details>sections🤖 Generated with Claude Code