-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(feedback): Ensure feedback can be lazy loaded in CDN bundles (#13241
) This was brought up in slack - if you use a CDN bundle (or the loader) without feedback included, and you try to lazy-load the feedbackIntegration, it fails as of today. The reason is that we check if `window.Sentry.feedbackIntegration` exists, which it _does_, because we register a shim integration for compatibility in the loader. So this PR adds a property on the shim integration which we can check for during lazy loading. While at it, I also added a missing method to the feedback integration shim.
- Loading branch information
Showing
6 changed files
with
80 additions
and
15 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...ckages/browser-integration-tests/suites/integrations/lazyLoad/feedbackIntegration/init.js
This file contains 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,10 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
integrations: [], | ||
}); | ||
|
||
window.Sentry = { | ||
...Sentry, | ||
}; |
7 changes: 7 additions & 0 deletions
7
...ges/browser-integration-tests/suites/integrations/lazyLoad/feedbackIntegration/subject.js
This file contains 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 @@ | ||
window._testLazyLoadIntegration = async function run() { | ||
const integration = await window.Sentry.lazyLoadIntegration('feedbackIntegration'); | ||
|
||
window.Sentry.getClient()?.addIntegration(integration()); | ||
|
||
window._integrationLoaded = true; | ||
}; |
38 changes: 38 additions & 0 deletions
38
...ckages/browser-integration-tests/suites/integrations/lazyLoad/feedbackIntegration/test.ts
This file contains 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,38 @@ | ||
import { expect } from '@playwright/test'; | ||
import { SDK_VERSION } from '@sentry/browser'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
|
||
sentryTest('it allows to lazy load the feedback integration', async ({ getLocalTestUrl, page }) => { | ||
const bundle = process.env.PW_BUNDLE || ''; | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.route(`https://browser.sentry-cdn.com/${SDK_VERSION}/feedback.min.js`, route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/javascript;', | ||
body: "window.Sentry.feedbackIntegration = () => ({ name: 'Feedback', attachTo: () => {} })", | ||
}); | ||
}); | ||
|
||
await page.goto(url); | ||
|
||
await page.waitForFunction('window.Sentry?.getClient()'); | ||
|
||
const integrationOutput1 = await page.evaluate('window.Sentry.feedbackIntegration?._isShim'); | ||
|
||
// Multiple cases are possible here: | ||
// 1. Bundle without feedback, should have _isShim property | ||
if (bundle.startsWith('bundle') && !bundle.includes('feedback')) { | ||
expect(integrationOutput1).toBe(true); | ||
} else { | ||
// 2. Either bundle with feedback, or ESM, should not have _isShim property | ||
expect(integrationOutput1).toBe(undefined); | ||
} | ||
|
||
await page.evaluate('window._testLazyLoadIntegration()'); | ||
await page.waitForFunction('window._integrationLoaded'); | ||
|
||
const integrationOutput2 = await page.evaluate('window.Sentry.feedbackIntegration?._isShim'); | ||
expect(integrationOutput2).toBe(undefined); | ||
}); |
This file contains 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 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 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