Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): Do not auto-reload doc.location. Fixes #4530 #4535

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 14 additions & 11 deletions ui/src/app/shared/components/error-notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ export const ErrorNotice = (props: {style?: CSSProperties; error: Error & {respo
const reloadAfterSeconds = props.reloadAfterSeconds || 120;
const reload = props.onReload || document.location.reload;
const [timeLeft, setTimeLeft] = useState(reloadAfterSeconds);
useEffect(() => {
if (!timeLeft) {
reload();
setTimeLeft(reloadAfterSeconds);
}
const intervalId = setInterval(() => {
setTimeLeft(timeLeft - 1);
}, 1000);
return () => clearInterval(intervalId);
}, [timeLeft]);
const canAutoReload = reload !== document.location.reload; // we cannot automatically call `document.location.reload`
if (canAutoReload) {
useEffect(() => {
if (!timeLeft) {
reload();
setTimeLeft(reloadAfterSeconds);
}
const intervalId = setInterval(() => {
setTimeLeft(timeLeft - 1);
}, 1000);
return () => clearInterval(intervalId);
}, [timeLeft]);
}
return (
<Notice style={props.style}>
<PhaseIcon value='Error' /> {props.error.message || 'Unknown error. Open your browser error console for more information.'}
{props.error.response && props.error.response.body && props.error.response.body.message && ': ' + props.error.response.body.message}:{' '}
<a onClick={() => reload()}>
<i className='fa fa-redo' /> Reload
</a>{' '}
{timeLeft}s
{canAutoReload && `${timeLeft}s`}
</Notice>
);
};