mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Fixed race condition in instant loading
This commit is contained in:
parent
21e9396db0
commit
80f1d3e37b
@ -25,7 +25,7 @@ import { ajax } from "rxjs/ajax"
|
|||||||
import {
|
import {
|
||||||
catchError,
|
catchError,
|
||||||
distinctUntilKeyChanged,
|
distinctUntilKeyChanged,
|
||||||
pluck,
|
map,
|
||||||
share,
|
share,
|
||||||
skip,
|
skip,
|
||||||
switchMap
|
switchMap
|
||||||
@ -56,7 +56,10 @@ interface WatchOptions {
|
|||||||
* to the same page, the request is effectively ignored (i.e. when only the
|
* to the same page, the request is effectively ignored (i.e. when only the
|
||||||
* fragment identifier changes).
|
* fragment identifier changes).
|
||||||
*
|
*
|
||||||
* In case the request fails, the location change is dispatched regularly.
|
* Theoretically, we could use `responseType: "document"`, but since all MkDocs
|
||||||
|
* links are relative, we need to make sure that the current location matches
|
||||||
|
* the document we just loaded. Otherwise any relative links in the document
|
||||||
|
* may use the old location.
|
||||||
*
|
*
|
||||||
* @param options - Options
|
* @param options - Options
|
||||||
*
|
*
|
||||||
@ -65,6 +68,7 @@ interface WatchOptions {
|
|||||||
export function watchDocumentSwitch(
|
export function watchDocumentSwitch(
|
||||||
{ location$ }: WatchOptions
|
{ location$ }: WatchOptions
|
||||||
): Observable<Document> {
|
): Observable<Document> {
|
||||||
|
const dom = new DOMParser()
|
||||||
return location$
|
return location$
|
||||||
.pipe(
|
.pipe(
|
||||||
distinctUntilKeyChanged("pathname"),
|
distinctUntilKeyChanged("pathname"),
|
||||||
@ -73,11 +77,14 @@ export function watchDocumentSwitch(
|
|||||||
/* Fetch document */
|
/* Fetch document */
|
||||||
switchMap(url => ajax({
|
switchMap(url => ajax({
|
||||||
url: url.href,
|
url: url.href,
|
||||||
responseType: "document",
|
responseType: "text",
|
||||||
withCredentials: true
|
withCredentials: true
|
||||||
})
|
})
|
||||||
.pipe<Document, Document>(
|
.pipe(
|
||||||
pluck("response"),
|
map(({ response }): Document => {
|
||||||
|
history.pushState({}, "", url.toString()) // TODO: abstract into function
|
||||||
|
return dom.parseFromString(response, "text/html")
|
||||||
|
}),
|
||||||
catchError(() => {
|
catchError(() => {
|
||||||
setLocation(url)
|
setLocation(url)
|
||||||
return NEVER
|
return NEVER
|
||||||
|
@ -113,11 +113,6 @@ export function setupInstantLoading(
|
|||||||
)
|
)
|
||||||
.subscribe(location$)
|
.subscribe(location$)
|
||||||
|
|
||||||
/* History: dispatch internal link */
|
|
||||||
push$.subscribe(({ url }) => {
|
|
||||||
history.pushState({}, "", url.toString())
|
|
||||||
})
|
|
||||||
|
|
||||||
/* History: debounce update of viewport offset */
|
/* History: debounce update of viewport offset */
|
||||||
viewport$
|
viewport$
|
||||||
.pipe(
|
.pipe(
|
||||||
|
Loading…
Reference in New Issue
Block a user