don't render the minimap if it fails to initialize the gl context (#3679)

So far 33 people have had tldraw crash due to getContext('webgl2')
returning null for some reason. Maybe it's to do with what kind of
graphics hardware they have available.

This PR adds a stopgap measure wherein the minimap manager just fails to
render anything on the canvas element instead of crashing the app.
Ideally we'd have better UX around this but that can wait.

I'm gonna hotfix this to dotcom.

### Change Type

<!--  Please select a 'Scope' label ️ -->

- [x] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff

<!--  Please select a 'Type' label ️ -->

- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know
This commit is contained in:
David Sheldrick 2024-05-02 12:20:02 +01:00 committed by GitHub
parent 9ba4f7cf2a
commit ffe3e7602c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -25,9 +25,19 @@ export function DefaultMinimap() {
const minimapRef = React.useRef<MinimapManager>() const minimapRef = React.useRef<MinimapManager>()
React.useEffect(() => { React.useEffect(() => {
const minimap = new MinimapManager(editor, rCanvas.current, container) try {
minimapRef.current = minimap const minimap = new MinimapManager(editor, rCanvas.current, container)
return minimapRef.current.close minimapRef.current = minimap
return minimapRef.current.close
} catch (e) {
editor.annotateError(e, {
origin: 'minimap',
willCrashApp: false,
})
setTimeout(() => {
throw e
})
}
}, [editor, container]) }, [editor, container])
const onDoubleClick = React.useCallback( const onDoubleClick = React.useCallback(