Skip to content

SMOODEV-3805: Keep Buffers intact in the S3 Next cache handler - #13

Merged
brentrager merged 1 commit into
mainfrom
SMOODEV-3805-cache-buffers
Oct 10, 2026
Merged

brentrager merged 1 commit into
mainfrom
SMOODEV-3805-cache-buffers

Conversation

@brentrager

@brentrager brentrager commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

serialize in sst/src/next/cache-handler.cjs never base64-encoded a Buffer. JSON.stringify calls Buffer#toJSON before the replacer, so the replacer saw { type: 'Buffer', data: [...] } and Buffer.isBuffer(v) was always false. APP_ROUTE bodies were stored as plain objects, and on every cache HIT Next wrote them out as the 15-byte text [object Object]. On smoo.ai that breaks /favicon.ico, /opengraph-image and /twitter-image (link previews and the browser tab icon).

Solution

  • serialize reads the raw value off the holder (this[k]), so Buffers become { __b64 } as intended.
  • deserialize also decodes the old { type: 'Buffer', data } shape, so entries already in S3 serve correctly without a purge.
  • node --test regression test (in-memory S3) plus a CI step; release 0.2.2.

Verification

  • pnpm test: 2/2 pass with the fix, 0/2 on the old code.
  • Reproduced in Node: the old round-trip gives isBuffer: false, String(body) === "[object Object]".

Jira: SMOODEV-3805

🤖 Generated with Claude Code

https://claude.ai/code/session_01UwsWFhUD6BK9mXkakhUUJ6

JSON.stringify calls Buffer#toJSON before the replacer, so the replacer never
saw a Buffer and APP_ROUTE bodies were stored as { type: 'Buffer', data }. On a
cache hit Next wrote that object as the 15-byte text "[object Object]", which
broke smoo.ai's favicon.ico, opengraph-image and twitter-image. serialize now
reads the raw value off the holder, and deserialize also decodes the old shape
so entries already in S3 serve correctly without a purge. Release 0.2.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UwsWFhUD6BK9mXkakhUUJ6
@changeset-bot

changeset-bot Bot commented Oct 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f2fc2f0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@brentrager
brentrager merged commit ae94c72 into main Oct 10, 2026
2 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