Skip to content
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

🐛 [RUMF-1449] fix Zone support when __symbol__ is missing #1872

Merged
merged 1 commit into from
Dec 13, 2022
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
9 changes: 8 additions & 1 deletion packages/core/src/tools/getZoneJsOriginalValue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { stubZoneJs } from '../../test/stubZoneJs'

import type { BrowserWindowWithZoneJs } from './getZoneJsOriginalValue'
import { getZoneJsOriginalValue } from './getZoneJsOriginalValue'
import { noop } from './utils'

Expand All @@ -22,11 +23,17 @@ describe('getZoneJsOriginalValue', () => {
expect(getZoneJsOriginalValue(object, 'name')).toBe(originalValue)
})

it("returns undefined if Zone is defined but didn't patch that method", () => {
it("returns the original value if Zone is defined but didn't patch that method", () => {
zoneJsStub = stubZoneJs()
expect(getZoneJsOriginalValue(object, 'name')).toBe(originalValue)
})

it('returns the original value if Zone is defined but does not define the __symbol__ function', () => {
zoneJsStub = stubZoneJs()
delete (window as BrowserWindowWithZoneJs).Zone!.__symbol__
expect(getZoneJsOriginalValue(object, 'name')).toBe(originalValue)
})

it('returns the original value if Zone did patch the method', () => {
zoneJsStub = stubZoneJs()
zoneJsStub.replaceProperty(object, 'name', noop)
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/tools/getZoneJsOriginalValue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export interface BrowserWindowWithZoneJs extends Window {
Zone?: {
__symbol__: (name: string) => string
// All Zone.js versions expose the __symbol__ method, but we observed that some website have a
// 'Zone' global variable unrelated to Zone.js, so let's consider this method optional
// nonetheless.
__symbol__?: (name: string) => string
}
}

Expand All @@ -23,7 +26,7 @@ export function getZoneJsOriginalValue<Target, Name extends keyof Target & strin
): Target[Name] {
const browserWindow = window as BrowserWindowWithZoneJs
let original: Target[Name] | undefined
if (browserWindow.Zone) {
if (browserWindow.Zone && typeof browserWindow.Zone.__symbol__ === 'function') {
original = (target as any)[browserWindow.Zone.__symbol__(name)]
}
if (!original) {
Expand Down