Skip to content

Commit 93d7d91

Browse files
yharaskrikAndrewKushnir
authored andcommitted
fix(common): use DOCUMENT token to query for preconnect links (#47353)
`PreconnectLinkChecker` checks to see if preconnect links have been added to the `<head>` element but uses `document` directly which does not exist when rendering in Angular Universal. This PR switches the `PreconnectLinkChecker` to use the `DOCUMENT` token instead so that the query works when SSR'ing PR Close #47353
1 parent 220d120 commit 93d7d91

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/common/src/directives/ng_optimized_image/preconnect_link_checker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export const PRECONNECT_CHECK_BLOCKLIST =
4949
*/
5050
@Injectable({providedIn: 'root'})
5151
export class PreconnectLinkChecker {
52+
private document = inject(DOCUMENT);
53+
5254
/**
5355
* Set of <link rel="preconnect"> tags found on this page.
5456
* The `null` value indicates that there was no DOM query operation performed.
@@ -66,7 +68,7 @@ export class PreconnectLinkChecker {
6668

6769
constructor() {
6870
assertDevMode('preconnect link checker');
69-
const win = inject(DOCUMENT).defaultView;
71+
const win = this.document.defaultView;
7072
if (typeof win !== 'undefined') {
7173
this.window = win;
7274
}
@@ -127,7 +129,7 @@ export class PreconnectLinkChecker {
127129
private queryPreconnectLinks(): Set<string> {
128130
const preconnectUrls = new Set<string>();
129131
const selector = 'link[rel=preconnect]';
130-
const links: HTMLLinkElement[] = Array.from(document.querySelectorAll(selector));
132+
const links: HTMLLinkElement[] = Array.from(this.document.querySelectorAll(selector));
131133
for (let link of links) {
132134
const url = getUrl(link.href, this.window!);
133135
preconnectUrls.add(url.origin);

0 commit comments

Comments
 (0)