Barazo default frontend barazo.forum

fix(plugins): defensive null checks for settingsSchema and dependents (#197)

The API may not return settingsSchema or dependents fields. Use
optional chaining and nullish coalescing to prevent Object.keys()
and .length crashes on undefined values.

authored by

Guido X Jansen and committed by
GitHub
6cb673ba 5a17c792

+4 -4
+1 -1
src/components/admin/plugins/plugin-card.tsx
··· 69 69 </div> 70 70 71 71 <div className="flex shrink-0 items-center gap-2"> 72 - {Object.keys(plugin.settingsSchema).length > 0 && ( 72 + {Object.keys(plugin.settingsSchema ?? {}).length > 0 && ( 73 73 <button 74 74 type="button" 75 75 onClick={() => onOpenSettings(plugin)}
+1 -1
src/components/admin/plugins/plugin-settings-modal.tsx
··· 55 55 </div> 56 56 57 57 <div className="space-y-4"> 58 - {Object.entries(plugin.settingsSchema).map(([key, schema]) => ( 58 + {Object.entries(plugin.settingsSchema ?? {}).map(([key, schema]) => ( 59 59 <SettingsField 60 60 key={key} 61 61 fieldKey={key}
+2 -2
src/hooks/admin/use-plugin-management.ts
··· 43 43 }, [fetchPlugins]) 44 44 45 45 const findDependentNames = (plugin: Plugin): string[] => { 46 - return plugin.dependents.map((depId) => { 46 + return (plugin.dependents ?? []).map((depId) => { 47 47 const dep = plugins.find((p) => p.id === depId) 48 48 return dep?.displayName ?? depId 49 49 }) 50 50 } 51 51 52 52 const handleToggle = async (plugin: Plugin) => { 53 - if (plugin.enabled && plugin.dependents.length > 0) { 53 + if (plugin.enabled && (plugin.dependents?.length ?? 0) > 0) { 54 54 const dependentNames = findDependentNames(plugin) 55 55 setDependencyWarning({ plugin, dependents: dependentNames }) 56 56 return