-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(web-vitals): Add error handling for invalid object keys in WeakMap
#18809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,16 @@ const instanceMap: WeakMap<object, unknown> = new WeakMap(); | |
| * identity object was previously used. | ||
| */ | ||
| export function initUnique<T>(identityObj: object, ClassObj: new () => T): T { | ||
| if (!instanceMap.get(identityObj)) { | ||
| instanceMap.set(identityObj, new ClassObj()); | ||
| try { | ||
| if (!instanceMap.get(identityObj)) { | ||
| instanceMap.set(identityObj, new ClassObj()); | ||
| } | ||
| return instanceMap.get(identityObj)! as T; | ||
| } catch (e) { | ||
| // --- START Sentry-custom code (try/catch wrapping) --- | ||
| // Fix for cases where identityObj is not a valid key for WeakMap (sometimes a problem in Safari) | ||
| // Just return a new instance without caching it in instanceMap | ||
| return new ClassObj(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test for fix PR per review rulesLow Severity · Bugbot Rules Per the review rules: "When reviewing a |
||
| } | ||
| return instanceMap.get(identityObj)! as T; | ||
| // --- END Sentry-custom code --- | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Is this issue easily reproducible? If so it'd be nice if we can somehow add a E2E test, if not I'm fine as is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, sadly it's not :/