Skip to content

Commit 897ac64

Browse files
committed
fix: document$ should not emit on anchor navigation (#154)
Signed-off-by: squidfunk <martin.donath@squidfunk.com>
1 parent ba2d3c6 commit 897ac64

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

dist/assets/javascripts/bundle.354a4b29.min.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/assets/javascripts/bundle.ee611ef6.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
</script>
274274
{% endblock %}
275275
{% block scripts %}
276-
<script src="{{ 'assets/javascripts/bundle.354a4b29.min.js' | url }}"></script>
276+
<script src="{{ 'assets/javascripts/bundle.ee611ef6.min.js' | url }}"></script>
277277
{% for script in config.extra_javascript %}
278278
{{ script | script_tag }}
279279
{% endfor %}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ import {
3737
distinctUntilKeyChanged,
3838
endWith,
3939
exhaustMap,
40+
filter,
4041
fromEvent,
4142
ignoreElements,
4243
map,
4344
merge,
4445
of,
46+
pairwise,
4547
share,
48+
startWith,
4649
switchMap,
4750
take,
4851
tap,
@@ -339,7 +342,10 @@ export function setupInstantNavigation(
339342
// reason, we fall back and use regular navigation, forcing a reload.
340343
const document$ =
341344
location$.pipe(
342-
distinctUntilKeyChanged("pathname"),
345+
startWith(getLocation()),
346+
pairwise(),
347+
filter(([prev, next]) => prev.pathname !== next.pathname),
348+
map(([, url]) => url),
343349
switchMap(url => requestHTML(url, { progress$ })
344350
.pipe(
345351
catchError(() => {
@@ -376,6 +382,18 @@ export function setupInstantNavigation(
376382
distinctUntilKeyChanged("hash"),
377383
),
378384

385+
// Handle hash changes on the current document, including the first anchor
386+
// click after the initial page load.
387+
location$.pipe(
388+
startWith(getLocation()),
389+
pairwise(),
390+
filter(([prev, next]) => (
391+
prev.pathname === next.pathname &&
392+
prev.hash !== next.hash
393+
)),
394+
map(([, url]) => url)
395+
),
396+
379397
// Handle instant navigation events that are triggered by the user clicking
380398
// on an anchor link with the same hash fragment as the current one in the
381399
// URL. It is essential that we only intercept those from instant navigation

0 commit comments

Comments
 (0)