Conversation
7c486ae to
1adf9b7
Compare
1b43fb1 to
16502c3
Compare
Script size changes
Totals
|
e236f39 to
39f0df9
Compare
- Upgrade react-router-dom from v5 to v6.27.0 - Remove react-router-dom-v5-compat dependency - Update React to 18.3.0 and Grafana packages to 12.2.0 - Migrate route imports and navigation to v6 APIs - Use locationService for programmatic navigation - Update webpack externals configuration
39f0df9 to
6ddf83b
Compare
Initialize @grafana/i18n before rendering scenes components. Workaround for grafana/scenes#1322
6ddf83b to
0b40406
Compare
ckbedwell
left a comment
There was a problem hiding this comment.
One super teeny tiny nit.
This is great and glad we've removed this tech debt -- one thing that I couldn't work out as I was reviewing this PR: when should we use hooks from react-router directly vs locationService -- I even noticed there is a hook in the runtime package called useLocationService.
Does it make sense to migrate everything to using the location service abstraction at some point in the future so we are removed from the implementation detail of react-router or is it encouraged for us to use its hooks and methods directly?
I read through the documentation and couldn't find an answer and spot-checking other plugins I think they are as equally split as we are...
src/components/Checkster/components/form/FormHttpAuthenticationField.tsx
Outdated
Show resolved
Hide resolved
|
@ckbedwell Good question,
They're complementary. |
Migrate to React Router v6
Closes #713
Problem
The application was using
react-router-dom-v5-compatas a bridge between React Router v5 and v6. This compatibility layer:Additionally, the test infrastructure relied on React Router v5 APIs through
@grafana/uicomponents (Link,TextLink) and@grafana/runtime'slocationService, which caused test failures after migrating to v6.Solution
This PR completes the migration to React Router v6 by:
Runtime changes:
react-router-domfrom v5-compat to v6.27.0react-router-dom-v5-compatdependency entirelyuseNavigate,useParams,useLocation)locationServicefrom@grafana/runtime==>
locationService.push()/replace()is preferred as it's a Grafana's abstraction, integrates with Grafana's location tracking/observability.useNavigate(), React Router's native hook, works but bypasses Grafana's layerTest infrastructure updates:
test/render.tsxto useRouterwithlocationService.getHistory()so both React Router and locationService share the same history instance@grafana/runtimemock forlocationServiceimplementation includinghistory.block()support required byConfirmLeavingPage@grafana/uimock forLinkandTextLinkcomponents to work without React Router v5 context (these components internally depend on v5)Dependencies:
@grafana/create-pluginto v6.7.8useReactRouterV6feature flagNotes
The test mocks for
@grafana/uicomponents (Link,TextLink) are necessary because these components internally use React Router v5 APIs. Once Grafana updates@grafana/uito support v6 natively these mocks should be simplified or removed.