Skip to content

Commit

Permalink
fix(ui): Do not auto-reload doc.location. Fixes #4530 (#4535)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec authored Nov 16, 2020
1 parent eebcb8b commit 564e69f
Showing 1 changed file with 14 additions and 11 deletions.
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>
);
};

0 comments on commit 564e69f

Please sign in to comment.