Skip to content

Commit 4fe8566

Browse files
JeanMecheAndrewKushnir
authored andcommitted
docs(docs-infra): do not cache the versions.json file (angular#62534)
Without the flag, the file gets inline in the transfer cache making the resource useless. PR Close angular#62534
1 parent 49813c5 commit 4fe8566

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

adev/src/app/core/services/version-manager.service.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,35 +52,46 @@ export class VersionManager {
5252
};
5353
});
5454

55+
// This handle the fallback if the resource fails.
5556
versions = computed(() => {
5657
return this.remoteVersions.hasValue() ? this.remoteVersions.value() : this.localVersions;
5758
});
5859

59-
remoteVersions = httpResource(() => 'https://angular.dev/assets/others/versions.json', {
60-
parse: (json) => {
61-
if (!Array.isArray(json)) {
62-
throw new Error('Invalid version data');
63-
}
64-
return json.map((v: unknown) => {
65-
if (
66-
v === undefined ||
67-
v === null ||
68-
typeof v !== 'object' ||
69-
!('version' in v) ||
70-
!('url' in v) ||
71-
typeof v.version !== 'string' ||
72-
typeof v.url !== 'string'
73-
) {
60+
// Yes this will trigger a cors error on localhost
61+
// but this is fine as we'll fallback to the local versions.json
62+
// which is the most up-to-date anyway.
63+
remoteVersions = httpResource(
64+
() => ({
65+
url: 'https://angular.dev/assets/others/versions.json',
66+
transferCache: false,
67+
cache: 'no-cache',
68+
}),
69+
{
70+
parse: (json: unknown) => {
71+
if (!Array.isArray(json)) {
7472
throw new Error('Invalid version data');
7573
}
74+
return json.map((v: unknown) => {
75+
if (
76+
v === undefined ||
77+
v === null ||
78+
typeof v !== 'object' ||
79+
!('version' in v) ||
80+
!('url' in v) ||
81+
typeof v.version !== 'string' ||
82+
typeof v.url !== 'string'
83+
) {
84+
throw new Error('Invalid version data');
85+
}
7686

77-
return {
78-
displayName: v.version,
79-
url: v.url,
80-
};
81-
});
87+
return {
88+
displayName: v.version,
89+
url: v.url,
90+
};
91+
});
92+
},
8293
},
83-
});
94+
);
8495

8596
currentDocsVersion = computed(() => {
8697
// In devmode the version is 0, so we'll target next (which is first on the list)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy