File tree Expand file tree Collapse file tree
packages/browser-utils/src/metrics/web-vitals/lib Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,8 +22,16 @@ const instanceMap: WeakMap<object, unknown> = new WeakMap();
2222 * identity object was previously used.
2323 */
2424export function initUnique < T > ( identityObj : object , ClassObj : new ( ) => T ) : T {
25- if ( ! instanceMap . get ( identityObj ) ) {
26- instanceMap . set ( identityObj , new ClassObj ( ) ) ;
25+ try {
26+ if ( ! instanceMap . get ( identityObj ) ) {
27+ instanceMap . set ( identityObj , new ClassObj ( ) ) ;
28+ }
29+ return instanceMap . get ( identityObj ) ! as T ;
30+ } catch ( e ) {
31+ // --- START Sentry-custom code (try/catch wrapping) ---
32+ // Fix for cases where identityObj is not a valid key for WeakMap (sometimes a problem in Safari)
33+ // Just return a new instance without caching it in instanceMap
34+ return new ClassObj ( ) ;
2735 }
28- return instanceMap . get ( identityObj ) ! as T ;
36+ // --- END Sentry-custom code ---
2937}
You can’t perform that action at this time.
0 commit comments