Skip to content

fix(docs): correct cookie counter example fallback#852

Open
caduvt wants to merge 1 commit into
elysiajs:mainfrom
caduvt:fix/cookie-counter-example
Open

fix(docs): correct cookie counter example fallback#852
caduvt wants to merge 1 commit into
elysiajs:mainfrom
caduvt:fix/cookie-counter-example

Conversation

@caduvt

@caduvt caduvt commented Jun 1, 2026

Copy link
Copy Markdown

Fixes inconsistencies in the first example of "Cookie" page, in playground. A more detailed explanation of the problem is given in the issue.

https://elysiajs.com/tutorial/patterns/cookie/

Fixes #851

Summary by CodeRabbit

  • Documentation
    • Updated the cookie pattern tutorial with improved code examples demonstrating clearer and more maintainable approaches to handling cookie values.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 13798944-85ba-426b-9847-5f9adcdaa4b8

📥 Commits

Reviewing files that changed from the base of the PR and between b8eced1 and 71f21da.

📒 Files selected for processing (1)
  • docs/tutorial/patterns/cookie/index.md

Walkthrough

The cookie pattern tutorial example is corrected to handle undefined values properly. The counter update now explicitly converts the cookie value using Number() and assigns the incremented result, fixing the previous logic where unary coercion occurred before the nullish coalescing operator, causing NaN fallback instead of 0.

Changes

Cookie Example Documentation Fix

Layer / File(s) Summary
Cookie counter fallback correction
docs/tutorial/patterns/cookie/index.md
Counter logic updated from const total = +visit.value ?? 0 and visit.value++ to const total = Number(visit.value ?? 0) and visit.value = total + 1, properly handling undefined values with correct operator precedence.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

✨ A cookie so sweet, yet undefined before ♡~
NaN was lurking, but now it's fixed for sure~ (´▽`)
Zero falls back when the value's not there~
Your counter's now safe, no more bugs to spare~ ♡

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(docs): correct cookie counter example fallback' directly and accurately describes the main change—fixing the cookie counter example's fallback logic.
Linked Issues check ✅ Passed The PR correctly addresses issue #851 by rewriting the counter update logic to use Number(visit.value ?? 0) instead of +visit.value ?? 0, properly handling the fallback when the cookie is undefined.
Out of Scope Changes check ✅ Passed The changes are limited to the cookie example documentation, directly addressing the fallback bug described in issue #851 with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Cookie example does not correctly fallback to 0 when value is undefined

1 participant