diff --git a/public/app/features/dashboard/containers/PublicDashboardPage.test.tsx b/public/app/features/dashboard/containers/PublicDashboardPage.test.tsx index da7f4a7bbb3..7ae9cedb1e3 100644 --- a/public/app/features/dashboard/containers/PublicDashboardPage.test.tsx +++ b/public/app/features/dashboard/containers/PublicDashboardPage.test.tsx @@ -2,7 +2,7 @@ import { render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import React from 'react'; import { Provider } from 'react-redux'; -import { Router } from 'react-router-dom'; +import { match, Router } from 'react-router-dom'; import { useEffectOnce } from 'react-use'; import { Props as AutoSizerProps } from 'react-virtualized-auto-sizer'; import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock'; @@ -248,6 +248,16 @@ describe('PublicDashboardPage', () => { }); }); + describe('When public dashboard changes', () => { + it('Should init again', async () => { + const { rerender } = setup(); + rerender({ match: { params: { accessToken: 'another-new-access-token' } } as unknown as match }); + await waitFor(() => { + expect(initDashboard).toHaveBeenCalledTimes(2); + }); + }); + }); + describe('Given a public dashboard with time range enabled', () => { it('Should render time range and refresh picker buttons', async () => { setup(undefined, { diff --git a/public/app/features/dashboard/containers/PublicDashboardPage.tsx b/public/app/features/dashboard/containers/PublicDashboardPage.tsx index ffdacffcbfd..451b3acfc3e 100644 --- a/public/app/features/dashboard/containers/PublicDashboardPage.tsx +++ b/public/app/features/dashboard/containers/PublicDashboardPage.tsx @@ -69,8 +69,7 @@ const PublicDashboardPage = (props: Props) => { keybindingSrv: context.keybindings, }) ); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [route.routeName, match.params.accessToken, context.keybindings, dispatch]); useEffect(() => { if (prevProps?.location.search !== location.search) { @@ -89,7 +88,7 @@ const PublicDashboardPage = (props: Props) => { getTimeSrv().setAutoRefresh(urlParams.refresh); } } - }, [prevProps, location.search, props.queryParams, dashboard?.timepicker.hidden]); + }, [prevProps, location.search, props.queryParams, dashboard?.timepicker.hidden, match.params.accessToken]); if (!dashboard) { return ;