From 4b5d69e090603fc90c830b07a6b039a6a6674955 Mon Sep 17 00:00:00 2001 From: sstephenson Date: Thu, 7 Mar 2019 16:39:53 -0600 Subject: [PATCH 1/3] Extract Location.currentLocation --- src/controller.ts | 2 +- src/history.ts | 2 +- src/location.ts | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/controller.ts b/src/controller.ts index 076c1be6..7f1bb0a4 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -95,7 +95,7 @@ export class Controller { // History startHistory() { - this.location = Location.wrap(window.location.toString()) + this.location = Location.currentLocation this.restorationIdentifier = uuid() this.history.start() this.history.replace(this.location, this.restorationIdentifier) diff --git a/src/history.ts b/src/history.ts index 6fd577fb..6573d3a6 100644 --- a/src/history.ts +++ b/src/history.ts @@ -46,7 +46,7 @@ export class History { if (this.shouldHandlePopState()) { const { turbolinks } = event.state if (turbolinks) { - const location = Location.wrap(window.location.toString()) + const location = Location.currentLocation const { restorationIdentifier } = turbolinks this.delegate.historyPoppedToLocationWithRestorationIdentifier(location, restorationIdentifier) } diff --git a/src/location.ts b/src/location.ts index 3f767015..ba5f1c44 100644 --- a/src/location.ts +++ b/src/location.ts @@ -1,6 +1,10 @@ export type Locatable = Location | string export class Location { + static get currentLocation() { + return this.wrap(window.location.toString()) + } + static wrap(locatable: Locatable): Location static wrap(locatable?: Locatable | null): Location | undefined static wrap(locatable: Locatable) { From 17719bb21941b9de6e230af731576afe1358b9ff Mon Sep 17 00:00:00 2001 From: sstephenson Date: Thu, 7 Mar 2019 17:51:08 -0600 Subject: [PATCH 2/3] Fall back to current location if lastRenderedLocation is unset By design, Controller#pageLoaded may not be called when loading Turbolinks with a + + + +
+

Async script

+

Async script 2

+
+ + diff --git a/src/tests/fixtures/async_script_2.html b/src/tests/fixtures/async_script_2.html new file mode 100644 index 00000000..89426fdb --- /dev/null +++ b/src/tests/fixtures/async_script_2.html @@ -0,0 +1,14 @@ + + + + + Turbolinks + + + + +
+

Async script 2

+
+ + diff --git a/src/tests/index.ts b/src/tests/index.ts index ac21fbed..06c15c1a 100644 --- a/src/tests/index.ts +++ b/src/tests/index.ts @@ -1,3 +1,4 @@ +export * from "./async_script_tests" export * from "./navigation_tests" export * from "./rendering_tests" export * from "./visit_tests"