1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-09-17 10:16:57 +00:00

Add an error catcher and error state for the chat scroller to hopefully allow chat to recover when React forgets how to DOM.

This commit is contained in:
SirStendec 2018-03-03 16:38:50 -05:00
parent a0606a49a4
commit 8ba8e054a5
3 changed files with 81 additions and 2 deletions

View file

@ -336,7 +336,9 @@ export default class ChatHook extends Module {
this.ChatController.ready((cls, instances) => {
const t = this,
old_catch = cls.prototype.componentDidCatch;
old_catch = cls.prototype.componentDidCatch,
old_render = cls.prototype.render;
// Try catching errors. With any luck, maybe we can
// recover from the error when we re-build?
cls.prototype.componentDidCatch = function(err, info) {
@ -351,6 +353,22 @@ export default class ChatHook extends Module {
return old_catch.call(this, err, info);
}
cls.prototype.render = function() {
if ( this.state.ffz_errors > 0 ) {
const React = t.web_munch.getModule('react'),
e = React && React.createElement;
if ( ! e )
return null;
return e('div', {
className: 'tw-border-l tw-c-background-alt-2 tw-c-text tw-full-width tw-full-height tw-align-items-center tw-flex tw-flex-column tw-justify-content-center tw-relative'
}, 'There was an error displaying chat.');
} else
return old_render.call(this);
}
for(const inst of instances) {
const service = inst.chatService;
if ( ! service._ffz_was_here )
@ -375,6 +393,7 @@ export default class ChatHook extends Module {
this.ChatContainer.ready((cls, instances) => {
const t = this,
old_catch = cls.prototype.componentDidCatch;
// Try catching errors. With any luck, maybe we can
// recover from the error when we re-build?
cls.prototype.componentDidCatch = function(err, info) {