Point og:image rasterizing at the shared og-svg renderer - #86
Open
alcor wants to merge 4 commits into
Open
Conversation
The old call built '/.netlify/functions/rasterize/' + svg as a path, but rasterize.js only ever read the query string, so every request 502'd. It also put unescaped SVG markup straight into a URL path. decodeURL has already base64-decoded the value by this point, so what we hold is SVG markup; it is re-encoded as base64url, which stays URL-safe with no percent-encoding and so fits more into Cloudflare's 16KB URL cap. Removes functions/rasterize.js and the sharp dependency it needed, plus the [functions] block that existed only to mark sharp external. Renderer: https://github.com/arfct/og-svg Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The old call built '/.netlify/functions/rasterize/' + svg as a path, but rasterize.js only ever read the query string, so every request 502'd. It also put unescaped SVG markup straight into a URL path. decodeURL has already base64-decoded the value by this point, so what we hold is SVG markup; it is re-encoded as base64url, which stays URL-safe with no percent-encoding and so fits more into Cloudflare's 16KB URL cap. Removes functions/rasterize.js and the sharp dependency it needed, plus the [functions] block that existed only to mark sharp external. Renderer: https://github.com/arfct/og-svg Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
In-progress editor chrome rework on the og-svg-renderer branch: - Relocate the doc-title metadata form from the page body into #formatbar, and add a params field plus a contenteditable #url-preview. - Turn 'show preview' from a menu link into a PREVIEW button in the toolbar. - Sketch a ShareForm class in bitty-menu.js for redirect.app share links. Incomplete: parse() still references undefined 'object' and 'dashspaces'. Committed to preserve work ahead of moving this repo out of Dropbox.
The same og:image rasterizing change was committed independently on both sides (ce065c4 locally, 0fde9b3 on origin), so the branches diverged 2/4. Everything auto-merged except package.json. package.json: both sides dropped the sharp dependency. Only origin touched devDependencies (removing netlify-cli); we left it untouched, so the conflict was textual, not semantic. Resolved to origin s version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Points
og:imagerasterizing at the shared og-svg renderer, and removes the local rasterizer that could never be reached.The bug
metadata.jsbuilt the rasterizer URL as a path:But
functions/rasterize.jsreadevent.rawQuery— the query string, never the path. Probed against production to confirm:/.netlify/functions/rasterize/svg:<b64>— as this code built it502/.netlify/functions/rasterize?<b64>— as the function read it200 image/jpeg, 8707 bytesThe rasterizer worked fine. Nothing ever called it correctly, so
i:-with-SVG links have been silently producing no preview image.There was a second failure layered on top. By this point
decodeURLhas already run, and this repo's version doesatob()with notry/catch. A payload that is not valid base64 throws, which the outertryswallows — killing all metadata for that page, not just the image.The fix
renderUrl()builds an og-svg URL from the SVG markupdecodeURLhas already produced.The payload is encoded as base64url, which stays URL-safe with no percent-encoding. That matters because Cloudflare caps URLs at 16KB, and percent-encoding raw markup is substantially more expensive — for the same test SVG, base64url produced a 346-character URL where percent-encoding produced 557.
Verified
Rendered against the live renderer:
The unicode case matters because
btoaalone throws on non-Latin-1 input; this reuses the existingutoahelper.Removed
functions/rasterize.js, thesharpdependency it needed, and the[functions]block that existed only to marksharpas an external module.sharpappeared nowhere else in the repo.Note on output format
og-svg returns PNG; the old rasterizer produced JPEG. Since no caller ever reached it successfully, there is no existing behaviour to stay compatible with, and every crawler accepts PNG.
Note on the base
This branch is rebased onto current
main(25aa3cd). The working copy it was authored in predated that commit, which had removed thedevDependenciesblock frompackage.json— rebasing rather than merging avoids silently re-addingnetlify-cli. The resulting diff topackage.jsonis only the removal ofsharp.🤖 Generated with Claude Code