-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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: reset perf logger timer for soft navigation for SPA pages #16668
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,15 @@ | |
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React, { Suspense } from 'react'; | ||
import React, { Suspense, useEffect } from 'react'; | ||
import { hot } from 'react-hot-loader/root'; | ||
import { Provider as ReduxProvider } from 'react-redux'; | ||
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'; | ||
import { | ||
BrowserRouter as Router, | ||
Switch, | ||
Route, | ||
useLocation, | ||
} from 'react-router-dom'; | ||
import { DndProvider } from 'react-dnd'; | ||
import { HTML5Backend } from 'react-dnd-html5-backend'; | ||
import { QueryParamProvider } from 'use-query-params'; | ||
|
@@ -34,6 +39,7 @@ import { theme } from 'src/preamble'; | |
import ToastPresenter from 'src/messageToasts/containers/ToastPresenter'; | ||
import setupApp from 'src/setup/setupApp'; | ||
import { routes, isFrontendRoute } from 'src/views/routes'; | ||
import { Logger } from 'src/logger/LogUtils'; | ||
import { store } from './store'; | ||
|
||
setupApp(); | ||
|
@@ -43,26 +49,39 @@ const bootstrap = JSON.parse(container?.getAttribute('data-bootstrap') ?? '{}'); | |
const user = { ...bootstrap.user }; | ||
const menu = { ...bootstrap.common.menu_data }; | ||
const common = { ...bootstrap.common }; | ||
let lastLocationPathname: string; | ||
initFeatureFlags(bootstrap.common.feature_flags); | ||
|
||
const RootContextProviders: React.FC = ({ children }) => ( | ||
<ThemeProvider theme={theme}> | ||
<ReduxProvider store={store}> | ||
<DndProvider backend={HTML5Backend}> | ||
<FlashProvider messages={common.flash_messages}> | ||
<DynamicPluginProvider> | ||
<QueryParamProvider | ||
ReactRouterRoute={Route} | ||
stringifyOptions={{ encode: false }} | ||
> | ||
{children} | ||
</QueryParamProvider> | ||
</DynamicPluginProvider> | ||
</FlashProvider> | ||
</DndProvider> | ||
</ReduxProvider> | ||
</ThemeProvider> | ||
); | ||
const RootContextProviders: React.FC = ({ children }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of putting this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic needs to stay with global route change. Do you mean to move this logic to root dashboard / list / welcome etc, each component? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean move it to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we chatted a little bit offline. Based on current way we use |
||
const location = useLocation(); | ||
useEffect(() => { | ||
// reset performance logger timer start point to avoid soft navigation | ||
// cause dashboard perf measurement problem | ||
if (lastLocationPathname && lastLocationPathname !== location.pathname) { | ||
Logger.markTimeOrigin(); | ||
} | ||
lastLocationPathname = location.pathname; | ||
}, [location.pathname]); | ||
|
||
return ( | ||
<ThemeProvider theme={theme}> | ||
<ReduxProvider store={store}> | ||
<DndProvider backend={HTML5Backend}> | ||
<FlashProvider messages={common.flash_messages}> | ||
<DynamicPluginProvider> | ||
<QueryParamProvider | ||
ReactRouterRoute={Route} | ||
stringifyOptions={{ encode: false }} | ||
> | ||
{children} | ||
</QueryParamProvider> | ||
</DynamicPluginProvider> | ||
</FlashProvider> | ||
</DndProvider> | ||
</ReduxProvider> | ||
</ThemeProvider> | ||
); | ||
}; | ||
|
||
const App = () => ( | ||
<Router> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
window.performance
API refers the start time as "time origin", so how about renaming the variables like: