-
Notifications
You must be signed in to change notification settings - Fork 146
TRT-2866: Upgrade react-router-dom to v8 in Sippy frontend #3960
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
base: main
Are you sure you want to change the base?
Changes from all commits
276063c
20fa5e1
09a2556
fc84607
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copy of use-query-params' ReactRouter6Adapter, importing from 'react-router' | ||
| // instead of 'react-router-dom' (which this project no longer depends on). | ||
| // The UNSAFE_ prefixed contexts are React Router's convention for internal APIs | ||
| // intentionally exported for library interop, not a security concern. | ||
| import { | ||
| UNSAFE_DataRouterContext, | ||
| UNSAFE_NavigationContext, | ||
| useLocation, | ||
| useNavigate, | ||
| } from 'react-router' | ||
| import { useContext } from 'react' | ||
|
|
||
| export const ReactRouterAdapter = ({ children }) => { | ||
| const { navigator } = useContext(UNSAFE_NavigationContext) | ||
| const navigate = useNavigate() | ||
| const router = useContext(UNSAFE_DataRouterContext)?.router | ||
| const location = useLocation() | ||
|
|
||
| const adapter = { | ||
| replace(location) { | ||
| navigate(location.search || '?', { | ||
| replace: true, | ||
| state: location.state, | ||
| }) | ||
| }, | ||
| push(location) { | ||
| navigate(location.search || '?', { | ||
| replace: false, | ||
| state: location.state, | ||
| }) | ||
| }, | ||
| get location() { | ||
| return router?.state?.location ?? navigator?.location ?? location | ||
| }, | ||
| } | ||
|
|
||
| return children(adapter) | ||
| } | ||
|
Comment on lines
+13
to
+38
Contributor
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. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: printf '%s\n' '--- scoped repository conventions ---'
find /tmp/coderabbit-repo-knowledge/openshift-sippy-86b0000f -type f -name '*.md' -maxdepth 3 -print
printf '%s\n' '--- changed file and nearby imports ---'
cat -n sippy-ng/src/adapters/ReactRouterAdapter.jsx | sed -n '1,90p'
printf '%s\n' '--- App wiring and direct adapter/provider references ---'
rg -n -C 4 'ReactRouterAdapter|QueryParamProvider|BrowserRouter' sippy-ng/src/App.jsx sippy-ng/src sippy-ng --glob '*.{js,jsx,ts,tsx,json}'
printf '%s\n' '--- frontend test files and package scripts ---'
find sippy-ng -type f \( -iname '*test*' -o -iname '*spec*' \) -print | sort | head -80
sed -n '1,180p' sippy-ng/package.jsonRepository: openshift/sippy Length of output: 17876 🏁 Script executed: printf '%s\n' '--- sippy-ng conventions ---'
cat /tmp/coderabbit-repo-knowledge/openshift-sippy-86b0000f/conventions/sippy-ng.md
printf '%s\n' '--- relevant repository-wide conventions ---'
cat /tmp/coderabbit-repo-knowledge/openshift-sippy-86b0000f/conventions/repo-wide.md
printf '%s\n' '--- change summary and adapter history in the reviewed snapshot ---'
git diff --stat 204c2fc76687c91c5702f0b4ecbdf37b625ce943 20fa5e1cad0cc3a797520342e54b1221a68ebddf -- sippy-ng
git diff --name-status 204c2fc76687c91c5702f0b4ecbdf37b625ce943 20fa5e1cad0cc3a797520342e54b1221a68ebddf -- sippy-ng
printf '%s\n' '--- provider/router nesting ---'
cat -n sippy-ng/src/index.jsx | sed -n '1,40p'
cat -n sippy-ng/src/App.jsx | sed -n '540,580p'
cat -n sippy-ng/src/App.jsx | sed -n '800,835p'
printf '%s\n' '--- adapter-specific tests or test imports ---'
rg -n -i 'ReactRouterAdapter|QueryParamProvider|BrowserRouter|use-query-params' sippy-ng --glob '*.{test,spec}.{js,jsx,ts,tsx}' || trueRepository: openshift/sippy Length of output: 28925 Add focused tests for Cover 🤖 Prompt for AI AgentsSources: Path instructions, MCP tools
Author
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. Done. Added AI-assisted response |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import '@testing-library/jest-dom' | ||
| import { act, render, screen } from '@testing-library/react' | ||
| import { BrowserRouter } from 'react-router' | ||
| import { | ||
| QueryParamProvider, | ||
| StringParam, | ||
| useQueryParam, | ||
| } from 'use-query-params' | ||
| import { ReactRouterAdapter } from './ReactRouterAdapter' | ||
| import React from 'react' | ||
|
|
||
| function TestComponent() { | ||
| const [value, setValue] = useQueryParam('foo', StringParam) | ||
| return ( | ||
| <div> | ||
| <span data-testid="value">{value ?? ''}</span> | ||
| <button onClick={() => setValue('bar')}>Set</button> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| function renderWithRouter(ui, { route = '/' } = {}) { | ||
| window.history.pushState({}, '', route) | ||
| return render( | ||
| <BrowserRouter> | ||
| <QueryParamProvider adapter={ReactRouterAdapter}>{ui}</QueryParamProvider> | ||
| </BrowserRouter> | ||
| ) | ||
| } | ||
|
|
||
| describe('ReactRouterAdapter', () => { | ||
| it('renders children via the adapter', () => { | ||
| renderWithRouter(<TestComponent />) | ||
| expect(screen.getByTestId('value')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('reads query params from the URL', () => { | ||
| renderWithRouter(<TestComponent />, { route: '/?foo=hello' }) | ||
| expect(screen.getByTestId('value')).toHaveTextContent('hello') | ||
| }) | ||
|
|
||
| it('updates query params on push', async () => { | ||
| renderWithRouter(<TestComponent />) | ||
| await act(async () => { | ||
| screen.getByText('Set').click() | ||
| }) | ||
| expect(window.location.search).toContain('foo=bar') | ||
| expect(screen.getByTestId('value')).toHaveTextContent('bar') | ||
| }) | ||
| }) |
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.
This looks...unsafe. what is this adapter doing for us?
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.
Good question. This adapter is a copy of
use-query-params' built-inReactRouter6Adapter, but importing fromreact-routerinstead ofreact-router-dom(which this PR removes). TheUNSAFE_prefix is React Router's naming convention for internal APIs intentionally exported for library interop — not a security concern. The upstream adapter uses the exact sameUNSAFE_contexts. Added comments to the file explaining this.AI-assisted response