Skip to content

ref: remove loading of assets in frontend #80893

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 1 commit into from
Nov 18, 2024
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
57 changes: 9 additions & 48 deletions static/app/plugins/registry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,18 @@ export default class Registry {
data: Plugin,
callback: (instance: DefaultIssuePlugin | DefaultPlugin | SessionStackPlugin) => void
) {
let remainingAssets = data.assets.length;
// TODO(dcramer): we should probably register all valid plugins
const finishLoad = () => {
if (!defined(this.plugins[data.id])) {
if (data.type === 'issue-tracking') {
this.plugins[data.id] = DefaultIssuePlugin;
} else {
this.plugins[data.id] = DefaultPlugin;
}
}
console.info(
'[plugins] Loaded ' + data.id + ' as {' + this.plugins[data.id].name + '}'
);
callback(this.get(data));
};

if (remainingAssets === 0) {
finishLoad();
return;
}

const onAssetLoaded = function () {
remainingAssets--;
if (remainingAssets === 0) {
finishLoad();
}
};

const onAssetFailed = function (asset: {url: string}) {
remainingAssets--;
console.error('[plugins] Failed to load asset ' + asset.url);
if (remainingAssets === 0) {
finishLoad();
}
};

// TODO(dcramer): what do we do on failed asset loading?
data.assets.forEach(asset => {
if (!defined(this.assetCache[asset.url])) {
console.info('[plugins] Loading asset for ' + data.id + ': ' + asset.url);
const s = document.createElement('script');
s.src = asset.url;
s.onload = onAssetLoaded.bind(this);
s.onerror = onAssetFailed.bind(this, asset);
s.async = true;
document.body.appendChild(s);
this.assetCache[asset.url] = s;
if (!defined(this.plugins[data.id])) {
if (data.type === 'issue-tracking') {
this.plugins[data.id] = DefaultIssuePlugin;
} else {
onAssetLoaded();
this.plugins[data.id] = DefaultPlugin;
}
});
}
console.info(
'[plugins] Loaded ' + data.id + ' as {' + this.plugins[data.id].name + '}'
);
callback(this.get(data));
}

get(data: Plugin) {
Expand Down
1 change: 0 additions & 1 deletion static/app/types/integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ export type IntegrationIssueConfig = {
* Project Plugins
*/
export type PluginNoProject = {
assets: Array<{url: string}>;
canDisable: boolean;
// TODO(ts)
contexts: any[];
Expand Down
3 changes: 0 additions & 3 deletions tests/js/fixtures/integrationListDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ export function SentryAppInstallsFixture() {
export function PluginListConfigFixture() {
return [
{
assets: [],
author: {name: 'Sentry Team', url: 'https://github.com/getsentry/sentry'},
canDisable: true,
contexts: [],
Expand Down Expand Up @@ -259,7 +258,6 @@ export function PluginListConfigFixture() {
hasConfiguration: true,
shortName: 'PagerDuty',
id: 'pagerduty',
assets: [],
featureDescriptions: [
{
description:
Expand Down Expand Up @@ -314,7 +312,6 @@ export function WebhookPluginConfigFixture(plugin?: Partial<Plugin>): Plugin {
metadata: {},
contexts: [],
status: 'unknown',
assets: [],
doc: '',
enabled: true,
version: '24.1.0.dev0',
Expand Down
1 change: 0 additions & 1 deletion tests/js/fixtures/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export function PluginFixture(params: Partial<Plugin> = {}): Plugin {
name: 'Amazon SQS',
slug: 'amazon-sqs',
version: '8.23.0.dev0',
assets: [],
hasConfiguration: true,
canDisable: true,
contexts: [],
Expand Down
Loading