Merge pull request #160 from alibaba/fix/extension-error-handling

fix: add button to clear saved configuration from the error boundary
This commit is contained in:
Simon
2026-03-07 23:22:41 +08:00
committed by GitHub

View File

@@ -1,4 +1,4 @@
import { AlertTriangle, RotateCcw } from 'lucide-react' import { AlertTriangle, Eraser, RotateCcw } from 'lucide-react'
import { Component, type ErrorInfo, type ReactNode } from 'react' import { Component, type ErrorInfo, type ReactNode } from 'react'
import { Button } from '@/components/ui/button' import { Button } from '@/components/ui/button'
@@ -27,6 +27,11 @@ export class ErrorBoundary extends Component<Props, State> {
window.location.reload() window.location.reload()
} }
handleResetConfig = async () => {
await chrome.storage.local.remove(['llmConfig', 'language', 'advancedConfig'])
window.location.reload()
}
render() { render() {
if (!this.state.hasError) { if (!this.state.hasError) {
return this.props.children return this.props.children
@@ -39,10 +44,16 @@ export class ErrorBoundary extends Component<Props, State> {
<p className="text-sm text-muted-foreground mb-4 max-w-xs"> <p className="text-sm text-muted-foreground mb-4 max-w-xs">
{this.state.error?.message || 'An unexpected error occurred'} {this.state.error?.message || 'An unexpected error occurred'}
</p> </p>
<Button variant="outline" size="sm" onClick={this.handleReload}> <div className="flex gap-2">
<RotateCcw className="size-3.5 mr-2" /> <Button variant="outline" size="sm" onClick={this.handleResetConfig}>
Reload Panel <Eraser className="size-3.5 mr-2" />
</Button> Reset Config
</Button>
<Button variant="outline" size="sm" onClick={this.handleReload}>
<RotateCcw className="size-3.5 mr-2" />
Reload Panel
</Button>
</div>
</div> </div>
) )
} }