/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import Loading from './ui/Loading';
import {
isChunkLoadError,
reloadForChunkError,
} from '../../helpers/chunkReload';
class ChunkErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { error: null, reloading: false };
}
static getDerivedStateFromError(error) {
return { error, reloading: false };
}
componentDidCatch(error) {
if (reloadForChunkError(error)) {
this.setState({ reloading: true });
}
}
render() {
const { error } = this.state;
if (!error) {
return this.props.children;
}
const chunkLoadError = isChunkLoadError(error);
if (chunkLoadError && this.state.reloading) {
return ;
}
return (
{chunkLoadError ? 'Page update required' : 'Something went wrong'}
{chunkLoadError
? 'The app was updated while this page was open. Refresh to load the latest files.'
: 'Please refresh the page and try again.'}