Skip to content

fix(card): coerce printing Decimal prices inside cache boundary#65

Merged
jcserv merged 1 commit into
mainfrom
fix-printing-decimal-cache
Jun 9, 2026
Merged

fix(card): coerce printing Decimal prices inside cache boundary#65
jcserv merged 1 commit into
mainfrom
fix-printing-decimal-cache

Conversation

@jcserv

@jcserv jcserv commented Jun 9, 2026

Copy link
Copy Markdown
Owner

getPrintingsForCard is 'use cache', which serializes its return value. Prisma Decimal price columns can't cross that boundary, so the card page threw "Decimal objects are not supported" before the page/route-level serializePrintings ever ran (errors surfaced with the Cache prefix).

The fix:

  • Coerce Decimal->number via serializePrintings inside getPrintingsForCard, so the cache only ever stores plain ClientPrinting objects
  • Rebase ClientPrinting/serializePrinting on the Prisma Printing model type instead of the query ReturnType, breaking the now-circular import
  • Drop the redundant serializePrintings wrap in the card page and printings API route
  • Update the query test to assert Decimal->number coercion

Description

Fixes: #

Checklist

  • Tests pass (pnpm test) and lint is clean
  • New behavior is covered by tests
  • No revalidate / dynamic / unstable_cache — used 'use cache' + cacheLife/cacheTag
  • <Link> imported from app/_components/link.tsx, not next/link
  • Suspense fallbacks reserve layout space (explicit heights)

Screenshots / notes

Summary by CodeRabbit

  • Refactor
    • Reorganized internal data serialization for card printing information to improve caching efficiency
    • Enhanced price data type consistency to ensure reliable numeric conversion across components

getPrintingsForCard is `'use cache'`, which serializes its return value.
Prisma Decimal price columns can't cross that boundary, so the card page
threw "Decimal objects are not supported" before the page/route-level
serializePrintings ever ran (errors surfaced with the `Cache` prefix).

The fix:
- Coerce Decimal->number via serializePrintings *inside* getPrintingsForCard,
  so the cache only ever stores plain ClientPrinting objects
- Rebase ClientPrinting/serializePrinting on the Prisma Printing model type
  instead of the query ReturnType, breaking the now-circular import
- Drop the redundant serializePrintings wrap in the card page and printings
  API route
- Update the query test to assert Decimal->number coercion
@jcserv jcserv self-assigned this Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 476603b2-3bf4-48de-96ef-b71658eebb02

📥 Commits

Reviewing files that changed from the base of the PR and between 53d0385 and ad91298.

📒 Files selected for processing (5)
  • app/(ui)/card/[slug]/page.tsx
  • app/api/cards/[id]/printings/route.ts
  • lib/card/__tests__/printing-queries.test.ts
  • lib/card/printing-queries.ts
  • lib/card/printing-types.ts

📝 Walkthrough

Walkthrough

This PR consolidates printing data serialization from the API route and page component into the query layer. getPrintingsForCard now returns pre-serialized ClientPrinting[] with price Decimal coercion occurring inside the cache boundary. Type contracts are updated to use the generated Printing type, and both callers are simplified.

Changes

Printing Serialization Consolidation

Layer / File(s) Summary
Printing type contracts and serialization signatures
lib/card/printing-types.ts
ClientPrinting is now sourced from the generated Printing type instead of the local DbPrinting. serializePrinting and serializePrintings signatures are updated to accept Printing[] with the same price coercion behavior.
Query layer serialization and caching
lib/card/printing-queries.ts
getPrintingsForCard now explicitly returns Promise<ClientPrinting[]> and applies serializePrintings to Prisma results within the "use cache" boundary, with documentation noting when Decimal coercion occurs.
Query test validation for price coercion
lib/card/__tests__/printing-queries.test.ts
Mocked Prisma results include priceUsd as a Decimal-like object. Assertion validates that getPrintingsForCard coerces the price to a number (12.5) and preserves null values for other price fields.
API route and page component consumer updates
app/api/cards/[id]/printings/route.ts, app/(ui)/card/[slug]/page.tsx
API route returns printings directly without serialization. Page component passes getPrintingsForCard output directly to PrintingCarousel without wrapping, both imports removed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 ✨ The printings dance with grace so true,
Serialized where they should be due,
From callers free, to queries deep inside,
Price fields coerced with proper pride—
Type contracts clean, the cache takes care,
Refactored flow beyond compare!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main fix: moving Decimal price coercion to occur inside the 'use cache' boundary of getPrintingsForCard to resolve serialization errors.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-printing-decimal-cache

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

app/(ui)/card/[slug]/page.tsx

Parsing error: The keyword 'import' is reserved

app/api/cards/[id]/printings/route.ts

Parsing error: The keyword 'import' is reserved

lib/card/__tests__/printing-queries.test.ts

Parsing error: The keyword 'import' is reserved

  • 2 others

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.

@jcserv jcserv merged commit 2c33be2 into main Jun 9, 2026
5 checks passed
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