Skip to content

Commit adafd84

Browse files
committed
Fixed invalid anchor offsets when using instant loading
1 parent 51d4920 commit adafd84

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

material/assets/javascripts/bundle.806c4996.min.js renamed to material/assets/javascripts/bundle.8fb3741f.min.js

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

material/assets/javascripts/bundle.806c4996.min.js.map renamed to material/assets/javascripts/bundle.8fb3741f.min.js.map

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

material/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ <h1>{{ page.title | d(config.site_name, true)}}</h1>
223223
</script>
224224
{% endblock %}
225225
{% block scripts %}
226-
<script src="{{ 'assets/javascripts/bundle.806c4996.min.js' | url }}"></script>
226+
<script src="{{ 'assets/javascripts/bundle.8fb3741f.min.js' | url }}"></script>
227227
{% for path in config["extra_javascript"] %}
228228
<script src="{{ path | url }}"></script>
229229
{% endfor %}

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

+30-17
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,23 @@ export function setupInstantLoading(
186186
/* Handle HTML and SVG elements */
187187
if (ev.target instanceof Element) {
188188
const el = ev.target.closest("a")
189-
if (el && !el.target && urls.includes(el.href)) {
190-
ev.preventDefault()
191-
return of({
192-
url: new URL(el.href)
193-
})
189+
if (el && !el.target) {
190+
const url = new URL(el.href)
191+
192+
/* Canonicalize URL */
193+
url.search = ""
194+
url.hash = ""
195+
196+
/* Check if URL should be intercepted */
197+
if (
198+
url.pathname !== location.pathname &&
199+
urls.includes(url.toString())
200+
) {
201+
ev.preventDefault()
202+
return of({
203+
url: new URL(el.href)
204+
})
205+
}
194206
}
195207
}
196208
return NEVER
@@ -252,18 +264,6 @@ export function setupInstantLoading(
252264
)
253265
.subscribe(document$)
254266

255-
/* Emit history state change */
256-
merge(push$, pop$)
257-
.pipe(
258-
sample(document$)
259-
)
260-
.subscribe(({ url, offset }) => {
261-
if (url.hash && !offset)
262-
setLocationHash(url.hash)
263-
else
264-
setViewportOffset(offset || { y: 0 })
265-
})
266-
267267
/* Replace meta tags and components */
268268
document$
269269
.pipe(
@@ -324,6 +324,19 @@ export function setupInstantLoading(
324324
)
325325
.subscribe()
326326

327+
/* Emit history state change */
328+
merge(push$, pop$)
329+
.pipe(
330+
sample(document$),
331+
)
332+
.subscribe(({ url, offset }) => {
333+
if (url.hash && !offset) {
334+
setLocationHash(url.hash)
335+
} else {
336+
setViewportOffset(offset || { y: 0 })
337+
}
338+
})
339+
327340
/* Debounce update of viewport offset */
328341
viewport$
329342
.pipe(

0 commit comments

Comments
 (0)