From ec1a16de96333b2cbbed99a2dc95ca800ba4e755 Mon Sep 17 00:00:00 2001 From: Alexander Brandon Coles Date: Mon, 25 May 2026 21:45:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#75046=20[hotwired?= =?UTF-8?q?=5F=5Fturbo]=20Add=20TurboHistory=20interface=20by=20@myabc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hotwired__turbo/hotwired__turbo-tests.ts | 27 +++++++++++++++++++ types/hotwired__turbo/index.d.ts | 16 ++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/types/hotwired__turbo/hotwired__turbo-tests.ts b/types/hotwired__turbo/hotwired__turbo-tests.ts index 4d6759313b4c53..4bc74319abaabc 100644 --- a/types/hotwired__turbo/hotwired__turbo-tests.ts +++ b/types/hotwired__turbo/hotwired__turbo-tests.ts @@ -15,6 +15,7 @@ import { StreamActions, StreamMessage, StreamSource, + TurboHistory, Visit, visit, VisitOptions, @@ -289,3 +290,29 @@ StreamMessage.contentType; // $ExpectType StreamMessage StreamMessage.wrap(""); + +// Test TurboHistory via session.history +// $ExpectType TurboHistory +session.history; +// $ExpectType TurboHistory +Turbo.session.history; + +session.history.push(new URL("https://example.com")); +session.history.push(new URL("https://example.com"), "abc-123"); +session.history.replace(new URL("https://example.com")); +session.history.replace(new URL("https://example.com"), "abc-123"); + +// $ExpectType URL +session.history.location; +// $ExpectType string +session.history.restorationIdentifier; + +// Test session getters +// $ExpectType URL +session.location; +// $ExpectType string +session.restorationIdentifier; +// $ExpectType boolean +session.started; +// $ExpectType boolean +session.enabled; diff --git a/types/hotwired__turbo/index.d.ts b/types/hotwired__turbo/index.d.ts index db2e65f42f58bd..bfd2d8a12449be 100644 --- a/types/hotwired__turbo/index.d.ts +++ b/types/hotwired__turbo/index.d.ts @@ -277,12 +277,26 @@ export function disconnectStreamSource(source: StreamSource): void; */ export function renderStreamMessage(message: StreamMessage | string): void; +export interface TurboHistory { + readonly location: URL; + readonly restorationIdentifier: string; + push(location: URL, restorationIdentifier?: string): void; + replace(location: URL, restorationIdentifier?: string): void; +} + export interface TurboSession { + readonly history: TurboHistory; + adapter: Adapter; + readonly enabled: boolean; + readonly started: boolean; + connectStreamSource(source: StreamSource): void; disconnectStreamSource(source: StreamSource): void; renderStreamMessage(message: StreamMessage | string): void; + drive: boolean; - adapter: Adapter; + readonly location: URL; + readonly restorationIdentifier: string; } export const StreamActions: {