Skip to content

Don't crash ogimage generation on RTL text #3341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-windows-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gitbook": patch
---

Don't crash ogimage generation on RTL text, as a workaround until we can support it.
3 changes: 3 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"assert-never": "^1.2.1",
"bun-types": "^1.1.20",
"classnames": "^2.5.1",
"direction": "^2.0.1",
"event-iterator": "^2.0.0",
"framer-motion": "^10.16.14",
"image-size": "^2.0.2",
Expand Down Expand Up @@ -1708,6 +1709,8 @@

"dir-glob": ["[email protected]", "", { "dependencies": { "path-type": "^4.0.0" } }, "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA=="],

"direction": ["[email protected]", "", { "bin": { "direction": "cli.js" } }, "sha512-9S6m9Sukh1cZNknO1CWAr2QAWsbKLafQiyM5gZ7VgXHeuaoUwffKN4q6NC4A/Mf9iiPlOXQEKW/Mv/mh9/3YFA=="],

"dlv": ["[email protected]", "", {}, "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA=="],

"dom-serializer": ["[email protected]", "", { "dependencies": { "domelementtype": "^2.3.0", "domhandler": "^5.0.2", "entities": "^4.2.0" } }, "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg=="],
Expand Down
3 changes: 2 additions & 1 deletion packages/gitbook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"zod": "^3.24.2",
"zod-to-json-schema": "^3.24.5",
"zustand": "^5.0.3",
"image-size": "^2.0.2"
"image-size": "^2.0.2",
"direction": "^2.0.1"
},
"devDependencies": {
"@argos-ci/playwright": "^5.0.3",
Expand Down
23 changes: 20 additions & 3 deletions packages/gitbook/src/routes/ogimage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CustomizationDefaultFont, CustomizationHeaderPreset } from '@gitbook/api';
import { colorContrast } from '@gitbook/colors';
import { type FontWeight, getDefaultFont } from '@gitbook/fonts';
import { direction } from 'direction';
import { imageSize } from 'image-size';
import { redirect } from 'next/navigation';
import { ImageResponse } from 'next/og';
Expand Down Expand Up @@ -218,7 +219,7 @@ export async function serveOGImage(baseContext: GitBookSiteContext, params: Page
) : (
<div tw="flex">
{favicon}
<h3 tw="text-4xl my-0 font-bold">{site.title}</h3>
<h3 tw="text-4xl my-0 font-bold">{transformText(site.title)}</h3>
</div>
)}

Expand All @@ -227,10 +228,12 @@ export async function serveOGImage(baseContext: GitBookSiteContext, params: Page
<h1
tw={`text-8xl my-0 tracking-tight leading-none text-left text-[${colors.title}] font-bold`}
>
{pageTitle}
{transformText(pageTitle)}
</h1>
{pageDescription ? (
<h2 tw="text-4xl mb-0 mt-8 w-[75%] font-normal">{pageDescription}</h2>
<h2 tw="text-4xl mb-0 mt-8 w-[75%] font-normal">
{transformText(pageDescription)}
</h2>
) : null}
</div>
</div>,
Expand Down Expand Up @@ -377,3 +380,17 @@ async function fetchImage(url: string) {
return null;
}
}

/**
* @vercel/og doesn't support RTL text, so we need to transform with a HACK for now.
* We can remove it once support has been added.
* https://github.com/vercel/satori/issues/74
*/
function transformText(text: string) {
const dir = direction(text);
if (dir !== 'rtl') {
return text;
}

return '';
}