diff --git a/packages/expo-notifications/CHANGELOG.md b/packages/expo-notifications/CHANGELOG.md index 5cb1d929236eb..d72e915f1885b 100644 --- a/packages/expo-notifications/CHANGELOG.md +++ b/packages/expo-notifications/CHANGELOG.md @@ -28,6 +28,7 @@ - Removed the large icon from managed workflow. ([#10492](https://github.com/expo/expo/pull/10492) by [@lukmccall](https://github.com/lukmccall)) - Fixed crash happening due to non-existent `ExpoNotificationsService` being declared in `AndroidManifest.xml`. ([#10638](https://github.com/expo/expo/pull/10638) by [@sjchmiela](https://github.com/sjchmiela)) - Fixed notifications _not_ playing any sound when `shouldShowAlert: false` but `shouldPlaySound: true` in `setNotificationHandler`. ([#10699](https://github.com/expo/expo/pull/10699) by [@cruzach](https://github.com/cruzach)) +- Add guard against badgin usage in SSR environments. ([#10741](https://github.com/expo/expo/pull/10741) by [@bycedric](https://github.com/bycedric)) ## 0.7.1 — 2020-08-26 diff --git a/packages/expo-notifications/build/BadgeModule.web.d.ts b/packages/expo-notifications/build/BadgeModule.web.d.ts index 73aa20f0621f1..027301abafa0d 100644 --- a/packages/expo-notifications/build/BadgeModule.web.d.ts +++ b/packages/expo-notifications/build/BadgeModule.web.d.ts @@ -1,3 +1,3 @@ import { BadgeModule } from './BadgeModule.types'; -declare const _default: BadgeModule; -export default _default; +declare const badgeModule: BadgeModule; +export default badgeModule; diff --git a/packages/expo-notifications/build/BadgeModule.web.js b/packages/expo-notifications/build/BadgeModule.web.js index 7657ca5505447..c68e69a786155 100644 --- a/packages/expo-notifications/build/BadgeModule.web.js +++ b/packages/expo-notifications/build/BadgeModule.web.js @@ -1,12 +1,17 @@ -import * as badgin from 'badgin'; let lastSetBadgeCount = 0; -export default { +const badgeModule = { addListener: () => { }, removeListeners: () => { }, getBadgeCountAsync: async () => { return lastSetBadgeCount; }, setBadgeCountAsync: async (badgeCount, options) => { + // If this module is loaded in SSR (NextJS), we can't modify the badge. + // It also can't load the badgin module, that instantly invokes methods on window. + if (typeof window === 'undefined') { + return false; + } + const badgin = require('badgin'); if (badgeCount > 0) { badgin.set(badgeCount, options); } @@ -17,4 +22,5 @@ export default { return true; }, }; +export default badgeModule; //# sourceMappingURL=BadgeModule.web.js.map \ No newline at end of file diff --git a/packages/expo-notifications/build/BadgeModule.web.js.map b/packages/expo-notifications/build/BadgeModule.web.js.map index cc911e53bcacb..ed090dca9395b 100644 --- a/packages/expo-notifications/build/BadgeModule.web.js.map +++ b/packages/expo-notifications/build/BadgeModule.web.js.map @@ -1 +1 @@ -{"version":3,"file":"BadgeModule.web.js","sourceRoot":"","sources":["../src/BadgeModule.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAIjC,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAE1B,eAAe;IACb,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;IACrB,eAAe,EAAE,GAAG,EAAE,GAAE,CAAC;IACzB,kBAAkB,EAAE,KAAK,IAAI,EAAE;QAC7B,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IACD,kBAAkB,EAAE,KAAK,EAAE,UAAkB,EAAE,OAAwB,EAAE,EAAE;QACzE,IAAI,UAAU,GAAG,CAAC,EAAE;YAClB,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;SACjC;aAAM;YACL,MAAM,CAAC,KAAK,EAAE,CAAC;SAChB;QACD,iBAAiB,GAAG,UAAU,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;CACa,CAAC","sourcesContent":["import * as badgin from 'badgin';\n\nimport { BadgeModule } from './BadgeModule.types';\n\nlet lastSetBadgeCount = 0;\n\nexport default {\n addListener: () => {},\n removeListeners: () => {},\n getBadgeCountAsync: async () => {\n return lastSetBadgeCount;\n },\n setBadgeCountAsync: async (badgeCount: number, options?: badgin.Options) => {\n if (badgeCount > 0) {\n badgin.set(badgeCount, options);\n } else {\n badgin.clear();\n }\n lastSetBadgeCount = badgeCount;\n return true;\n },\n} as BadgeModule;\n"]} \ No newline at end of file +{"version":3,"file":"BadgeModule.web.js","sourceRoot":"","sources":["../src/BadgeModule.web.ts"],"names":[],"mappings":"AAEA,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAE1B,MAAM,WAAW,GAAgB;IAC/B,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;IACrB,eAAe,EAAE,GAAG,EAAE,GAAE,CAAC;IACzB,kBAAkB,EAAE,KAAK,IAAI,EAAE;QAC7B,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IACD,kBAAkB,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE;QAChD,uEAAuE;QACvE,kFAAkF;QAClF,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YACjC,OAAO,KAAK,CAAC;SACd;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QACjC,IAAI,UAAU,GAAG,CAAC,EAAE;YAClB,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;SACjC;aAAM;YACL,MAAM,CAAC,KAAK,EAAE,CAAC;SAChB;QACD,iBAAiB,GAAG,UAAU,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import { BadgeModule } from './BadgeModule.types';\n\nlet lastSetBadgeCount = 0;\n\nconst badgeModule: BadgeModule = {\n addListener: () => {},\n removeListeners: () => {},\n getBadgeCountAsync: async () => {\n return lastSetBadgeCount;\n },\n setBadgeCountAsync: async (badgeCount, options) => {\n // If this module is loaded in SSR (NextJS), we can't modify the badge.\n // It also can't load the badgin module, that instantly invokes methods on window.\n if (typeof window === 'undefined') {\n return false;\n }\n const badgin = require('badgin');\n if (badgeCount > 0) {\n badgin.set(badgeCount, options);\n } else {\n badgin.clear();\n }\n lastSetBadgeCount = badgeCount;\n return true;\n },\n};\n\nexport default badgeModule;\n"]} \ No newline at end of file diff --git a/packages/expo-notifications/src/BadgeModule.web.ts b/packages/expo-notifications/src/BadgeModule.web.ts index b3b5006e0b051..fd023ff31ac54 100644 --- a/packages/expo-notifications/src/BadgeModule.web.ts +++ b/packages/expo-notifications/src/BadgeModule.web.ts @@ -1,16 +1,20 @@ -import * as badgin from 'badgin'; - import { BadgeModule } from './BadgeModule.types'; let lastSetBadgeCount = 0; -export default { +const badgeModule: BadgeModule = { addListener: () => {}, removeListeners: () => {}, getBadgeCountAsync: async () => { return lastSetBadgeCount; }, - setBadgeCountAsync: async (badgeCount: number, options?: badgin.Options) => { + setBadgeCountAsync: async (badgeCount, options) => { + // If this module is loaded in SSR (NextJS), we can't modify the badge. + // It also can't load the badgin module, that instantly invokes methods on window. + if (typeof window === 'undefined') { + return false; + } + const badgin = require('badgin'); if (badgeCount > 0) { badgin.set(badgeCount, options); } else { @@ -19,4 +23,6 @@ export default { lastSetBadgeCount = badgeCount; return true; }, -} as BadgeModule; +}; + +export default badgeModule;