Skip to content

Commit 183b0be

Browse files
committed
Fixed anchor links in closed details when using instant loading
1 parent ab23604 commit 183b0be

File tree

7 files changed

+35
-21
lines changed

7 files changed

+35
-21
lines changed

material/assets/javascripts/bundle.20c9977b.min.js renamed to material/assets/javascripts/bundle.19047be9.min.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/assets/javascripts/bundle.19047be9.min.js.map

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/assets/javascripts/bundle.20c9977b.min.js.map

-8
This file was deleted.

material/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
</script>
241241
{% endblock %}
242242
{% block scripts %}
243-
<script src="{{ 'assets/javascripts/bundle.20c9977b.min.js' | url }}"></script>
243+
<script src="{{ 'assets/javascripts/bundle.19047be9.min.js' | url }}"></script>
244244
{% for path in config.extra_javascript %}
245245
<script src="{{ path | url }}"></script>
246246
{% endfor %}

src/assets/javascripts/browser/location/hash/index.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
filter,
2626
fromEvent,
2727
map,
28+
merge,
2829
shareReplay,
2930
startWith
3031
} from "rxjs"
@@ -66,10 +67,17 @@ export function setLocationHash(hash: string): void {
6667
/**
6768
* Watch location hash
6869
*
70+
* @param location$ - Location observable
71+
*
6972
* @returns Location hash observable
7073
*/
71-
export function watchLocationHash(): Observable<string> {
72-
return fromEvent<HashChangeEvent>(window, "hashchange")
74+
export function watchLocationHash(
75+
location$: Observable<URL>
76+
): Observable<string> {
77+
return merge(
78+
fromEvent<HashChangeEvent>(window, "hashchange"),
79+
location$
80+
)
7381
.pipe(
7482
map(getLocationHash),
7583
startWith(getLocationHash()),
@@ -81,10 +89,14 @@ export function watchLocationHash(): Observable<string> {
8189
/**
8290
* Watch location target
8391
*
92+
* @param location$ - Location observable
93+
*
8494
* @returns Location target observable
8595
*/
86-
export function watchLocationTarget(): Observable<HTMLElement> {
87-
return watchLocationHash()
96+
export function watchLocationTarget(
97+
location$: Observable<URL>
98+
): Observable<HTMLElement> {
99+
return watchLocationHash(location$)
88100
.pipe(
89101
map(id => getOptionalElement(`[id="${id}"]`)!),
90102
filter(el => typeof el !== "undefined")

src/assets/javascripts/bundle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ document.documentElement.classList.add("js")
127127
/* Set up navigation observables and subjects */
128128
const document$ = watchDocument()
129129
const location$ = watchLocation()
130-
const target$ = watchLocationTarget()
130+
const target$ = watchLocationTarget(location$)
131131
const keyboard$ = watchKeyboard()
132132

133133
/* Set up media observables */

src/assets/javascripts/integrations/instant/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ export function setupInstantLoading(
141141
// We now know that we have a link to an internal page, so we prevent
142142
// the browser from navigation and emit the URL for instant navigation.
143143
// Note that this also includes anchor links, which means we need to
144-
// implement anchor positioning ourselves.
144+
// implement anchor positioning ourselves. The reason for this is that
145+
// if we wouldn't manage anchor links as well, scroll restoration will
146+
// not work correctly (e.g. following an anchor link and scrolling).
145147
ev.preventDefault()
146148
return of(new URL(el.href))
147149
}),
@@ -284,7 +286,7 @@ export function setupInstantLoading(
284286
// Intercept popstate events, e.g. when using the browser's back and forward
285287
// buttons, and emit new location for fetching and parsing.
286288
const popstate$ = fromEvent<PopStateEvent>(window, "popstate")
287-
popstate$.pipe(map(() => getLocation()))
289+
popstate$.pipe(map(getLocation))
288290
.subscribe(location$)
289291

290292
// Intercept clicks on anchor links, and scroll document into position. As

0 commit comments

Comments
 (0)