-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser): Add moduleMetadataIntegration lazy loading support #13817
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cab40cd
feat(browser): Add moduleMetadataIntegration lazy loading support
gilisho f9b9b84
Fix file formatting
gilisho 56fd358
Add test to make sure moduleMetadataIntegration can be lazy loaded
gilisho a0cc6b5
Update dev-packages/browser-integration-tests/suites/integrations/laz…
gilisho 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
12 changes: 12 additions & 0 deletions
12
.../browser-integration-tests/suites/integrations/lazyLoad/moduleMetadataIntegration/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,12 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
integrations: [], | ||
}); | ||
|
||
window.Sentry = { | ||
...Sentry, | ||
// Ensure this is _not_ set | ||
moduleMetadataIntegration: undefined, | ||
}; |
7 changes: 7 additions & 0 deletions
7
...owser-integration-tests/suites/integrations/lazyLoad/moduleMetadataIntegration/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,7 @@ | ||
window._testLazyLoadIntegration = async function run() { | ||
const integration = await window.Sentry.lazyLoadIntegration('moduleMetadataIntegration'); | ||
|
||
window.Sentry.getClient()?.addIntegration(integration()); | ||
|
||
window._integrationLoaded = true; | ||
}; |
33 changes: 33 additions & 0 deletions
33
.../browser-integration-tests/suites/integrations/lazyLoad/moduleMetadataIntegration/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,33 @@ | ||
import { expect } from '@playwright/test'; | ||
import { SDK_VERSION } from '@sentry/browser'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
|
||
sentryTest('it allows to lazy load the moduleMetadata integration', async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.route(`https://browser.sentry-cdn.com/${SDK_VERSION}/modulemetadata.min.js`, route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/javascript;', | ||
body: "window.Sentry.moduleMetadataIntegration = () => ({ name: 'ModuleMetadata' })", | ||
}); | ||
}); | ||
|
||
await page.goto(url); | ||
|
||
const hasIntegration = await page.evaluate('!!window.Sentry.getClient()?.getIntegrationByName("ModuleMetadata")'); | ||
expect(hasIntegration).toBe(false); | ||
|
||
const scriptTagsBefore = await page.evaluate<number>('document.querySelectorAll("script").length'); | ||
|
||
await page.evaluate('window._testLazyLoadIntegration()'); | ||
await page.waitForFunction('window._integrationLoaded'); | ||
|
||
const scriptTagsAfter = await page.evaluate<number>('document.querySelectorAll("script").length'); | ||
|
||
const hasIntegration2 = await page.evaluate('!!window.Sentry.getClient()?.getIntegrationByName("ModuleMetadata")'); | ||
expect(hasIntegration2).toBe(true); | ||
|
||
expect(scriptTagsAfter).toBe(scriptTagsBefore + 1); | ||
}); |
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
1 change: 1 addition & 0 deletions
1
packages/browser/src/integrations-bundle/index.modulemetadata.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 @@ | ||
export { moduleMetadataIntegration } from '@sentry/core'; |
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.
Uh oh!
There was an error while loading. Please reload this page.