Skip to content

Commit

Permalink
src/app/item-page: try/catch for Altmetric and Dimensions
Browse files Browse the repository at this point in the history
Use try/catch on Altmetric and Dimensions components to avoid spam
about missing window, self, and document in SSR.
  • Loading branch information
alanorth committed Sep 30, 2024
1 parent b6e086d commit a78d0f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export class ItemPageAltmetricFieldComponent extends ItemPageFieldComponent impl
ngAfterViewInit() {
// Altmetric embed.js
import('./embed.js');
window['_altmetric_embed_init']();
try {
window['_altmetric_embed_init']();

Check failure on line 21 in src/app/item-page/simple/field-components/specific-field/altmetric/item-page-altmetric-field.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

["_altmetric_embed_init"] is better written in dot notation

Check failure on line 21 in src/app/item-page/simple/field-components/specific-field/altmetric/item-page-altmetric-field.component.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

["_altmetric_embed_init"] is better written in dot notation
} catch {

Check failure on line 22 in src/app/item-page/simple/field-components/specific-field/altmetric/item-page-altmetric-field.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Empty block statement

Check failure on line 22 in src/app/item-page/simple/field-components/specific-field/altmetric/item-page-altmetric-field.component.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Empty block statement

}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export class ItemPageDimensionsFieldComponent extends ItemPageFieldComponent imp
ngAfterViewInit() {
// Dimensions badge.js
import('./badge.js');

try {
window['__dimensions_embed'].addBadges();

Check failure on line 22 in src/app/item-page/simple/field-components/specific-field/dimensions/item-page-dimensions-field.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

["__dimensions_embed"] is better written in dot notation

Check failure on line 22 in src/app/item-page/simple/field-components/specific-field/dimensions/item-page-dimensions-field.component.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

["__dimensions_embed"] is better written in dot notation
} catch {

Check failure on line 23 in src/app/item-page/simple/field-components/specific-field/dimensions/item-page-dimensions-field.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Empty block statement

Check failure on line 23 in src/app/item-page/simple/field-components/specific-field/dimensions/item-page-dimensions-field.component.ts

View workflow job for this annotation

GitHub Actions / tests (20.x)

Empty block statement

}
}

/**
Expand Down

0 comments on commit a78d0f6

Please sign in to comment.