Skip to content

hx-upsert: only sort inserted elements when sort is set - #4228

Open
cestercian wants to merge 1 commit into
bigskysoftware:four-devfrom
cestercian:fix/upsert-sort-only-when-asked
Open

cestercian wants to merge 1 commit into
bigskysoftware:four-devfrom
cestercian:fix/upsert-sort-only-when-asked

Conversation

@cestercian

Copy link
Copy Markdown

Description

hx-upsert was inserting new keyed elements in sorted order even when sort was not set. The modifier was already parsed (hx-swap="upsert sort" / sort:desc, and the sort attribute on <hx-upsert>), but handle_swap never checked swapSpec.sort.

Without sort, new elements are appended. With prepend and no sort, they go at the start, in the order they appear in the response. sort and sort:desc still sort the same way as before.

Before, a target with item-1, item-3 and a response of new item-2 plus updated item-3 (hx-swap="upsert") came out 1, 2, 3. It now stays 1, 3, 2.

Corresponding issue: Fixes #4226

Testing

Added tests in test/tests/ext/hx-upsert.js:

  • no sort appends new keyed elements, and an updated element stays where it was
  • prepend without sort inserts new keyed elements at the start, in response order
  • sort and sort:desc still sort
  • the same cases through <hx-partial hx-swap="upsert"> and the <hx-upsert> tag

npm run test passed (1854 passed, 0 failed, 4 skipped). Also ran python3 src/scripts/content/check.py. There is no lint script in package.json. Left dist/ alone.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

New keyed elements were placed in sorted order even when the
sort modifier was omitted. Append them, or prepend them when
that modifier is set, unless sort or sort:desc is requested.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant