Skip to content

Make sort order using sortby more consistent#9747

Open
pmario wants to merge 2 commits intoTiddlyWiki:masterfrom
pmario:sortby-order-fix-8342
Open

Make sort order using sortby more consistent#9747
pmario wants to merge 2 commits intoTiddlyWiki:masterfrom
pmario:sortby-order-fix-8342

Conversation

@pmario
Copy link
Copy Markdown
Member

@pmario pmario commented Mar 16, 2026

Fix sortby filter operator placing unlisted items first instead of last

Summary

The sortby filter operator incorrectly placed items not present in the reference list at the beginning of the results instead of at the end. This is because indexOf() returns -1 for unlisted items, which is smaller than any valid index, causing them to sort to the front.

How to test

  1. Create a tiddler called MyList with a list field containing: Alpha Beta Gamma
  2. Create five tiddlers — Alpha, Beta, Gamma, Delta, Epsilon — all tagged MyTag
  3. Run the filter: [tag[MyTag]sortby{MyList!!list}]
Scenario Before (broken) After (fixed)
[tag[MyTag]sortby{MyList!!list}] Delta Epsilon Alpha Beta Gamma Alpha Beta Gamma Delta Epsilon
[tag[MyTag]sortby{MyList!!list}reverse[]] Gamma Beta Alpha Epsilon Delta Epsilon Delta Gamma Beta Alpha

Expected behavior: Listed items appear in the order defined by the reference list, and unlisted items appear at the end (in their original relative order). With reverse[], the entire result is reversed.

Compatibility Risk

Minimal — this is a single-operator fix in the sort comparator. Existing uses of sortby where all items are present in the reference list are unaffected, since indexOf() never returns -1 in that case.

TODO

The release note needs a backwards compatibility notice too

Fixes: #8342

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 16, 2026

Deploy Preview for tiddlywiki-previews ready!

Name Link
🔨 Latest commit 77137c2
🔍 Latest deploy log https://app.netlify.com/projects/tiddlywiki-previews/deploys/69b834ad19eb6200089ab473
😎 Deploy Preview https://deploy-preview-9747--tiddlywiki-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown

Confirmed: pmario has already signed the Contributor License Agreement (see contributing.md)

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 16, 2026

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2487.2 KB
PR 2487.4 KB

Diff: ⬆️ Increase: +0.2 KB


⚠️ Change Note Status

This PR appears to contain code changes but doesn't include a change note.

Please add a change note by creating a .tid file in editions/tw5.com/tiddlers/releasenotes/<version>/

📚 Documentation: Release Notes and Changes

💡 Note: If this is a documentation-only change, you can ignore this message.

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.

[BUG] Incorrect sort order when using sortby[...] filter operator

1 participant