Skip to content

New default empty state#99

Open
z-tofu wants to merge 1 commit intojourney-ad:masterfrom
z-tofu:master
Open

New default empty state#99
z-tofu wants to merge 1 commit intojourney-ad:masterfrom
z-tofu:master

Conversation

@z-tofu
Copy link
Copy Markdown

@z-tofu z-tofu commented Mar 24, 2026

The Problem

Currently, if a user explicitly passes ?num=0 (or 00, which happened to me when building a clock that hit the top of the minute/hour), the counter ignores the override and acts as a standard page-hit counter instead.

This happens because the Zod schema defaults to 0, the route destructuring defaults to 0, and the getCountByName function explicitly checks if (num > 0) to bypass the database. Because 0 is not greater than 0, it falls through to the database increment logic.

The Solution

This PR introduces -1 as the new default "empty" state, allowing the backend to differentiate between "the user didn't provide a number" and "the user explicitly wants to display zero."

Changes Made:

  • Zod Schema: Lowered the min constraint of num to -1 and updated the default to -1.
  • Route Destructuring: Updated the fallback value of num from 0 to -1 in the app.get route.
  • Function Logic: Updated the manual override check in getCountByName from if (num > 0) to if (num >= 0).

Testing & Impact

  • Backwards Compatible: Yes. Standard hit-counter requests (where num is omitted) will now default to -1. Since -1 is not >= 0, they will safely fall through to the standard database increment logic just like before.
  • Fixes: Users can now successfully render the 0 or 00 images by passing ?num=0.

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