Skip to content

sortByDate sorts null/missing dates to the TOP in descending order #23

Description

@ManningWorks

Problem

sortByDate(projects, 'desc') (the default "newest first") sorts projects with no date (updatedAt and createdAt both null) to the TOP, ahead of every dated project:

// dist/lib/sortByDate.js
const dateA = a.updatedAt || a.createdAt || null
if (!dateA) return 1 * multiplier   // desc: multiplier -1 → returns -1 → a sorts BEFORE b

For desc (multiplier -1) a dateless row returns -1 → sorts before any dated row → rendered as "newest".

Why it's surprising

A project with no date appearing as the "newest" is the opposite of what a reader expects. Least-surprising behaviour is for dateless rows to sort to the bottom in "newest first" (treated as oldest/unknown).

There's also an asymmetry that makes it hard to reason about: the same dateless row sorts to the bottom in asc (returns +1) but to the top in desc. So a dateless project flips between first and last depending on sort direction.

Proposal

Treat null as the oldest (epoch-equivalent) so position is consistent and predictable — dateless sorts last in newest-first, first in oldest-first. Or expose an explicit nullsLast / nullsFirst option.

Concrete trigger

A devto project with no manual dates surfaced as "newest" in a consumer's projects list. The root cause for that project having no date at all is #22 (dev.to contributes no live date); but even setting that aside, the null-to-top-in-desc rule is independently surprising.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions