From 9b3148affd69f96f549f3d322abcc40876a5ae15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oddbj=C3=B8rn=20=C3=98vernes?= Date: Tue, 20 Aug 2024 11:00:26 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9BSnackbar:=20fix=20setTimeout=20runn?= =?UTF-8?q?ing=20every=20render=20(#3591)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Snackbar/Snackbar.stories.tsx | 39 +++++++++++++++++++ .../src/components/Snackbar/Snackbar.tsx | 3 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/eds-core-react/src/components/Snackbar/Snackbar.stories.tsx b/packages/eds-core-react/src/components/Snackbar/Snackbar.stories.tsx index dd1400f0b6..29c482fc85 100644 --- a/packages/eds-core-react/src/components/Snackbar/Snackbar.stories.tsx +++ b/packages/eds-core-react/src/components/Snackbar/Snackbar.stories.tsx @@ -80,3 +80,42 @@ export const WithAction: StoryFn = () => { ) } WithAction.storyName = 'With action' + +export const TimerRegressionTest: StoryFn = () => { + const [message, setMessage] = useState({ open: false, text: '' }) + const [data, setData] = useState(0) + + const handleClick = () => { + setMessage({ open: !message.open, text: 'Hello, World!' }) + } + + const handleDataClick = () => { + setData(data + 1) + } + + return ( + <> +
+ + +
+ + setMessage({ open: false, text: '' })} + autoHideDuration={2000} + > + {message.text} + + + ) +} +TimerRegressionTest.storyName = + 'Test to ensure timer stays consistent across rerenders' +//hide this story from sidebar +TimerRegressionTest.tags = ['!dev'] diff --git a/packages/eds-core-react/src/components/Snackbar/Snackbar.tsx b/packages/eds-core-react/src/components/Snackbar/Snackbar.tsx index dfa26f7572..33de1153b4 100644 --- a/packages/eds-core-react/src/components/Snackbar/Snackbar.tsx +++ b/packages/eds-core-react/src/components/Snackbar/Snackbar.tsx @@ -119,7 +119,8 @@ export const Snackbar = forwardRef( }, autoHideDuration) } return () => clearTimeout(timer.current) - }, [open, setVisible, autoHideDuration, onClose]) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [open, autoHideDuration]) const props = { ref,