Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/angular/ssr/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,17 @@ export class AngularServerApp {
return this.assets.getServerAsset(fileName);
});

if (isSsrMode) {
// TODO(alanagius): remove once Node.js version 18 is no longer supported.
if (isSsrMode && typeof crypto === 'undefined') {
// eslint-disable-next-line no-console
console.error(
`The global 'crypto' module is unavailable. ` +
`If you are running on Node.js, please ensure you are using version 20 or later, ` +
`which includes built-in support for the Web Crypto module.`,
);
}

if (isSsrMode && typeof crypto !== 'undefined') {
// Only cache if we are running in SSR Mode.
const cacheKey = await sha256(html);
let htmlWithCriticalCss = this.criticalCssLRUCache.get(cacheKey);
Expand Down
9 changes: 0 additions & 9 deletions packages/angular/ssr/src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
* represented as a hexadecimal string.
*/
export async function sha256(data: string): Promise<string> {
if (typeof crypto === 'undefined') {
// TODO(alanagius): remove once Node.js version 18 is no longer supported.
throw new Error(
`The global 'crypto' module is unavailable. ` +
`If you are running on Node.js, please ensure you are using version 20 or later, ` +
`which includes built-in support for the Web Crypto module.`,
);
}

const encodedData = new TextEncoder().encode(data);
const hashBuffer = await crypto.subtle.digest('SHA-256', encodedData);
const hashParts: string[] = [];
Expand Down