diff --git a/src/adapter/next/handler.ts b/src/adapter/next/handler.ts index 509ff7bb3..aa16c9eee 100644 --- a/src/adapter/next/handler.ts +++ b/src/adapter/next/handler.ts @@ -43,6 +43,7 @@ export function createHandler( first: true, select: Entry.url, id: info.entryId, + locale: info.locale, preview: payload ? {payload} : undefined }) if (!url) return new Response('Not found', {status: 404}) diff --git a/src/backend/Handler.ts b/src/backend/Handler.ts index 35e2ac2da..d0c627670 100644 --- a/src/backend/Handler.ts +++ b/src/backend/Handler.ts @@ -33,6 +33,7 @@ const PrepareBody = object({ }) const PreviewBody = object({ + locale: string.nullable, entryId: string }) diff --git a/src/backend/Previews.ts b/src/backend/Previews.ts index e7bde6481..9c53b6199 100644 --- a/src/backend/Previews.ts +++ b/src/backend/Previews.ts @@ -1,4 +1,5 @@ export interface PreviewInfo { + locale: string | null entryId: string } diff --git a/src/core/Preview.ts b/src/core/Preview.ts index 49f0c5cc6..c838d579a 100644 --- a/src/core/Preview.ts +++ b/src/core/Preview.ts @@ -11,6 +11,7 @@ export interface PreviewPayload { export type PreviewRequest = PreviewPayload | {entry: EntryRow} export interface PreviewUpdate { + locale: string | null entryId: string contentHash: string status: string diff --git a/src/dashboard/atoms/EntryEditorAtoms.ts b/src/dashboard/atoms/EntryEditorAtoms.ts index e0309b2df..e09ea9a26 100644 --- a/src/dashboard/atoms/EntryEditorAtoms.ts +++ b/src/dashboard/atoms/EntryEditorAtoms.ts @@ -734,6 +734,7 @@ export function createEntryEditor(entryData: EntryData) { const update = get(yUpdate) const status = get(selectedStatus) return encodePreviewPayload({ + locale: activeVersion.locale, entryId: activeVersion.id, contentHash, status: status, @@ -753,7 +754,10 @@ export function createEntryEditor(entryData: EntryData) { const previewToken = atom(async get => { const client = get(clientAtom) - return client.previewToken({entryId: entryData.entryId}) + return client.previewToken({ + locale: activeVersion.locale, + entryId: entryData.entryId + }) }) return { diff --git a/src/preview/PreviewPayload.ts b/src/preview/PreviewPayload.ts index 64dc62c0a..4810b6476 100644 --- a/src/preview/PreviewPayload.ts +++ b/src/preview/PreviewPayload.ts @@ -5,6 +5,7 @@ import * as encoding from 'lib0/encoding.js' export function encodePreviewPayload(update: PreviewUpdate): Promise { const encoder = encoding.createEncoder() + encoding.writeVarString(encoder, update.locale ?? '') encoding.writeVarString(encoder, update.entryId) encoding.writeVarString(encoder, update.contentHash) encoding.writeVarString(encoder, update.status) @@ -17,6 +18,7 @@ export async function decodePreviewPayload( ): Promise { const decoder = decoding.createDecoder(new Uint8Array(await decode(payload))) return { + locale: decoding.readVarString(decoder) || null, entryId: decoding.readVarString(decoder), contentHash: decoding.readVarString(decoder), status: decoding.readVarString(decoder),