-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(core): Call getCurrentHubShim
when accessing __SENTRY__.hub
#12160
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
dev-packages/browser-integration-tests/suites/old-sdk-interop/hub/init.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
}); |
9 changes: 9 additions & 0 deletions
9
dev-packages/browser-integration-tests/suites/old-sdk-interop/hub/subject.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
console.log(window.__SENTRY__); | ||
/** | ||
* Simulate an old pre v8 SDK obtaining the hub from the global sentry carrier | ||
* and checking for the hub version. | ||
*/ | ||
const res = window && window.__SENTRY__ && window.__SENTRY__.hub && window.__SENTRY__.hub.isOlderThan(7); | ||
|
||
// Write back result into the document | ||
document.getElementById('olderThan').innerText = res; |
9 changes: 9 additions & 0 deletions
9
dev-packages/browser-integration-tests/suites/old-sdk-interop/hub/template.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<p id="olderThan"></p> | ||
</body> | ||
</html> |
13 changes: 13 additions & 0 deletions
13
dev-packages/browser-integration-tests/suites/old-sdk-interop/hub/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
|
||
sentryTest( | ||
"doesn't crash if older SDKs access `hub.isOlderThan` on the global object", | ||
async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
await expect(page.locator('#olderThan')).toHaveText('false'); | ||
}, | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import type { Client, EventHint, Hub, Integration, IntegrationClass, SeverityLevel } from '@sentry/types'; | ||
import type { Client, EventHint, Hub, Integration, IntegrationClass, Scope, SeverityLevel } from '@sentry/types'; | ||
import { addBreadcrumb } from './breadcrumbs'; | ||
import { getClient, getCurrentScope, getIsolationScope, withScope } from './currentScopes'; | ||
import { | ||
|
@@ -22,7 +22,10 @@ import { | |
* usage | ||
*/ | ||
// eslint-disable-next-line deprecation/deprecation | ||
export function getCurrentHubShim(): Hub { | ||
export function getCurrentHubShim(): Hub & { | ||
getStackTop: () => { client: Client | undefined; scope: Scope }; | ||
isOlderThan: () => boolean; | ||
} { | ||
return { | ||
Comment on lines
+25
to
+28
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. Just noticed: We actually export this publicly from @sentry/core (not sure why we did this at all). Do we care that we widen the return type here? |
||
bindClient(client: Client): void { | ||
const scope = getCurrentScope(); | ||
|
@@ -64,6 +67,13 @@ export function getCurrentHubShim(): Hub { | |
// only send the update | ||
_sendSessionUpdate(); | ||
}, | ||
getStackTop: () => ({ | ||
client: getClient(), | ||
scope: getCurrentScope(), | ||
}), | ||
isOlderThan() { | ||
return false; | ||
}, | ||
}; | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Second oof: Referencing
getCurrentHubShim
here actually increases bundle size by +1% because previously,getCurrentHub(Shim)
was completely optional :(