Skip to content

Commit a7c7110

Browse files
committed
Fixed relative images not being resolved for instant navigation
1 parent bcad9ce commit a7c7110

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

material/templates/assets/javascripts/bundle.caa56a14.min.js renamed to material/templates/assets/javascripts/bundle.8fd75fb4.min.js

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

material/templates/assets/javascripts/bundle.caa56a14.min.js.map renamed to material/templates/assets/javascripts/bundle.8fd75fb4.min.js.map

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

material/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
</script>
250250
{% endblock %}
251251
{% block scripts %}
252-
<script src="{{ 'assets/javascripts/bundle.caa56a14.min.js' | url }}"></script>
252+
<script src="{{ 'assets/javascripts/bundle.8fd75fb4.min.js' | url }}"></script>
253253
{% for script in config.extra_javascript %}
254254
{{ script | script_tag }}
255255
{% endfor %}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,22 @@ function head(document: Document): Map<string, HTMLElement> {
145145
/**
146146
* Resolve relative URLs in the given document
147147
*
148+
* This function resolves relative `href` and `src` attributes, which can belong
149+
* to all sorts of tags, like meta tags, links, images, scripts and more.
150+
*
148151
* @param document - Document
149152
*
150153
* @returns Document observable
151154
*/
152155
function resolve(document: Document): Observable<Document> {
153-
for (const el of getElements<HTMLLinkElement>("[href], [src]", document))
154-
for (const key in ["href", "src"]) {
156+
for (const el of getElements("[href], [src]", document))
157+
for (const key of ["href", "src"]) {
155158
const value = el.getAttribute(key)
156-
if (!/^(?:[a-z]+:)?\/\//i.test(value!))
157-
el.href = el.href
159+
if (value && !/^(?:[a-z]+:)?\/\//i.test(value)) {
160+
// @ts-expect-error - trick: self-assign to resolve URL
161+
el[key] = el[key]
162+
break
163+
}
158164
}
159165

160166
// Return document observable

0 commit comments

Comments
 (0)