fix(web): TDZ crash in add-extension (installIconURL before installInfo)

installIconURL was computed above the useState declaration of installInfo,
causing "Cannot access 'installInfo' before initialization" (500) on the
add-extension page. Move the computation below the state declarations.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Junyan Qin
2026-06-01 19:25:19 +08:00
parent e2ca5cc70d
commit 4aeafe5a16

View File

@@ -162,19 +162,6 @@ function AddExtensionContent() {
: type === 'skill'
? t('market.typeSkill')
: t('market.typePlugin');
// Marketplace icon URL for the extension being installed, by type.
const buildInstallIconURL = () => {
const cloud = getCloudServiceClientSync();
const a = installInfo.plugin_author || '';
const n = installInfo.plugin_name || '';
if (installExtensionType === 'mcp')
return cloud.getMCPMarketplaceIconURL(a, n);
if (installExtensionType === 'skill')
return cloud.getSkillMarketplaceIconURL(a, n);
return cloud.getPluginIconURL(a, n);
};
const installIconURL = buildInstallIconURL();
const {
addTask,
setSelectedTaskId,
@@ -191,6 +178,19 @@ function AddExtensionContent() {
useState<PluginInstallStatus>(PluginInstallStatus.ASK_CONFIRM);
const [installError, setInstallError] = useState<string | null>(null);
const [installIconFailed, setInstallIconFailed] = useState(false);
// Marketplace icon URL for the extension being installed, by type.
const installIconURL = (() => {
const cloud = getCloudServiceClientSync();
const a = installInfo.plugin_author || '';
const n = installInfo.plugin_name || '';
if (installExtensionType === 'mcp')
return cloud.getMCPMarketplaceIconURL(a, n);
if (installExtensionType === 'skill')
return cloud.getSkillMarketplaceIconURL(a, n);
return cloud.getPluginIconURL(a, n);
})();
const [popoverOpen, setPopoverOpen] = useState(false);
const [popoverView, setPopoverView] = useState<PopoverView>('menu');
const [isDragOver, setIsDragOver] = useState(false);