Skip to content

Commit 2b82121

Browse files
committed
surround chrome code with a try catch to handle bugs on web browser
1 parent dbdd573 commit 2b82121

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/components/Changelog.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,29 @@ function Changelog({}) {
1313
const [changelogMarkdown, setChangelogMarkdown] = useState([])
1414
const [loading, setLoading] = useState(true)
1515
const [error, setError] = useState(null)
16-
const localAppVersion = chrome?.runtime?.getManifest()?.version || ''
16+
const [localAppVersion, setLocalAppVersion] = useState('')
1717
const preferences = useContext(PreferencesContext)
1818
const { dispatcher, changelogMeta } = preferences
1919
const [isChangelogRead, setIsChangelogRead] = useState(false)
2020

2121
const afterShow = () => {
22-
dispatcher({ type: 'setChangelogMeta', value: { shown: true, version: localAppVersion } })
2322
if (changelogMarkdown.length === 0) {
23+
dispatcher({ type: 'setChangelogMeta', value: { shown: true, version: localAppVersion } })
2424
fetchChangelog()
2525
}
2626
}
2727

2828
useEffect(() => {
2929
setIsChangelogRead(changelogMeta?.shown == true && changelogMeta?.version == localAppVersion)
30-
}, [changelogMeta])
30+
}, [localAppVersion, changelogMeta])
31+
32+
useEffect(() => {
33+
try {
34+
setLocalAppVersion(chrome.runtime.getManifest().version)
35+
} catch (e) {
36+
setLocalAppVersion('')
37+
}
38+
}, [])
3139

3240
const fetchChangelog = async () => {
3341
setLoading(true)
@@ -84,8 +92,8 @@ function Changelog({}) {
8492
) : (
8593
changelogMarkdown.map((item) => {
8694
return (
87-
<>
88-
<div className="tooltipHeader" key={item.name}>
95+
<div key={item.version}>
96+
<div className="tooltipHeader">
8997
<a className="tooltipVersion" onClick={(e) => window.open(item.url, '_blank')}>
9098
{item.version}
9199
</a>
@@ -94,7 +102,7 @@ function Changelog({}) {
94102
<div className="tooltipContent">
95103
<ReactMarkdown children={item.body} />
96104
</div>
97-
</>
105+
</div>
98106
)
99107
})
100108
)}

0 commit comments

Comments
 (0)