Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/js/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { ReactNode } from 'react'
import { createRoot } from 'react-dom/client'
import 'url-search-params-polyfill'

import { RouterProvider } from 'react-router-dom'
import { RouterProvider } from 'react-router'
import { createAppRouter } from './dashboard/router'
import ErrorBoundary from './dashboard/error/error-boundary'
import * as api from './dashboard/api'
Expand Down
2 changes: 1 addition & 1 deletion assets/js/dashboard/error/something-went-wrong.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactNode } from 'react'
import RocketIcon from '../stats/modals/rocket-icon'
import { useInRouterContext } from 'react-router-dom'
import { useInRouterContext } from 'react-router'
import { PlausibleSite } from '../site-context'
import { getRouterBasepath, rootRoute } from '../router'
import { AppNavigationLink } from '../navigation/use-app-navigate'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactNode } from 'react'
import { act, renderHook } from '@testing-library/react'
import { useNavigate } from 'react-router-dom'
import { useNavigate } from 'react-router'
import { TestContextProviders } from '../../../test-utils/app-context-providers'
import { useDashboardStateContext } from '../dashboard-state-context'
import { Filter } from '../dashboard-state'
Expand Down
19 changes: 10 additions & 9 deletions assets/js/dashboard/filtering/filter-editor-context.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import React, {
createContext,
ReactNode,
startTransition,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
useState
} from 'react'
import {
NavigationType,
useLocation,
useNavigationType
} from 'react-router-dom'
import { NavigationType, useLocation, useNavigationType } from 'react-router'
import { useDashboardStateContext } from '../dashboard-state-context'
import { useAppNavigate } from '../navigation/use-app-navigate'
import { Filter, FilterClauseLabels } from '../dashboard-state'
Expand Down Expand Up @@ -182,10 +179,14 @@ export const FilterEditorContextProvider = ({
mergedKey: filter[1],
mergedLabels: labels
})
setEditing({
...current,
draft: null,
hasPushedHistoryEntry: true
// react-router applies the URL change in a transition, so the draft must
// be cleared in one too, or the filter disappears between the two commits
startTransition(() => {
setEditing({
...current,
draft: null,
hasPushedHistoryEntry: true
Comment on lines +182 to +188

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix looks flimsier than I'd like, but manual testing confirms that it's working. We have previously talked about refactoring this module to do less, but haven't gotten to it, so maybe it's acceptable to have this hacky fix until we do.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's another case right above (the setEditing call in the if (!hasValues(filter)) branch, line 167) that should be wrapped with startTransition:

  1. Add a "Source is Google" filter
  2. Open its value picker
  3. De-select Google
  4. Notice how a second pill flickers next to the one we're currently editing

I agree that it's acceptable as a patch, but would be nice to fix it properly by making sure the filters pills are rendered based on a single source of truth.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah damn, thanks for finding that! Let's do it right then.

})
})
},
[setEditing, dashboardState.filters, navigateToFilters]
Expand Down
2 changes: 1 addition & 1 deletion assets/js/dashboard/nav-menu/dashboard-options-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IntervalPicker } from '../stats/graph/interval-picker'
import { AppNavigationLink } from '../navigation/use-app-navigate'
import { Notice } from '../components/notice'
import { isModifierPressed, isTyping, Keybind } from '../keybinding'
import { useMatch } from 'react-router-dom'
import { useMatch } from 'react-router'
import { rootRoute } from '../router'
import { CsvExport, ExportStatus } from '../stats/csv-export/csv-export'
import { MenuSeparator } from './nav-menu-components'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { TestContextProviders } from '../../../../test-utils/app-context-providers'
import { stringifySearch } from '../../util/url-search-params'
import { useNavigate } from 'react-router-dom'
import { useNavigate } from 'react-router'
import { getRouterBasepath } from '../../router'
import { DashboardPeriodPicker } from './dashboard-period-picker'
import { mockAnimationsApi, mockResizeObserver } from 'jsdom-testing-mocks'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
isComparisonForbidden,
isComparisonEnabled
} from '../../dashboard-time-periods'
import { useMatch } from 'react-router-dom'
import { useMatch } from 'react-router'
import { rootRoute } from '../../router'
import { Popover, Transition } from '@headlessui/react'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useSiteContext } from '../../site-context'
import { NavigateKeybind } from '../../keybinding'
import { AppNavigationLink } from '../../navigation/use-app-navigate'
import { DashboardPeriod } from '../../dashboard-time-periods'
import { useMatch } from 'react-router-dom'
import { useMatch } from 'react-router'
import { rootRoute } from '../../router'
import { isDateRangeCalendarOpen } from './date-range-calendar'

Expand Down
2 changes: 1 addition & 1 deletion assets/js/dashboard/navigation/use-app-navigate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Params,
NavigateOptions,
LinkProps
} from 'react-router-dom'
} from 'react-router'
import { parseSearch, stringifySearch } from '../util/url-search-params'
import { useSegmentsContext } from '../filtering/segments-context'
import { getSearchToSetSegmentFilter } from '../filtering/segments'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useState } from 'react'
import { useLocation } from 'react-router-dom'
import { useLocation } from 'react-router'
import { useAppNavigate } from './use-app-navigate'

/**
Expand Down
8 changes: 2 additions & 6 deletions assets/js/dashboard/router.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { createBrowserRouter, Outlet, useRouteError } from 'react-router-dom'
import { createBrowserRouter, Outlet, useRouteError } from 'react-router'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'

import { PlausibleSite, useSiteContext } from './site-context'
Expand Down Expand Up @@ -261,11 +261,7 @@ export function createAppRouter(site: PlausibleSite) {
}
],
{
basename: basepath,
future: {
// @ts-expect-error valid according to docs (https://reactrouter.com/en/main/routers/create-browser-router#optsfuture)
v7_prependBasename: true
}
basename: basepath
}
)

Expand Down
2 changes: 1 addition & 1 deletion assets/js/dashboard/site-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useQuery } from '@tanstack/react-query'
import { Role, useUserContext } from './user-context'
import { PlausibleSite, useSiteContext } from './site-context'
import { MenuSeparator } from './nav-menu/nav-menu-components'
import { useMatch } from 'react-router-dom'
import { useMatch } from 'react-router'
import { rootRoute } from './router'
import { get } from './api'
import { ErrorPanel } from './components/error-panel'
Expand Down
2 changes: 1 addition & 1 deletion assets/js/dashboard/stats/modals/props.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback } from 'react'
import { useParams } from 'react-router-dom'
import { useParams } from 'react-router'

import Modal from './modal'
import {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/dashboard/verification/portal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { act, render, screen } from '@testing-library/react'
import { useLocation } from 'react-router-dom'
import { useLocation } from 'react-router'
import { TestContextProviders } from '../../../test-utils/app-context-providers'
import {
VERIFICATION_FINISHED_EVENT,
Expand Down
Loading
Loading