Skip to content
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: Routing bug on uninitialised plugin #628

Merged
merged 8 commits into from
Oct 17, 2023
Merged

Conversation

ckbedwell
Copy link
Contributor

@ckbedwell ckbedwell commented Oct 13, 2023

Problem

When the plugin is uninitialised, when clicking different routes the screen blinks with rendering the route you clicked on before being redirected to the home page. The same behaviour happens for the un-provisioned state of the plugin.

Screen.Recording.2023-10-13.at.15.24.46.mov

Solution

I've removed the Setup and Provisioned routes and simply return early so that the other routes don't exist yet. I've added a useLayoutEffect to reroute back to home so that the breadcrumbs and side nav display correctly. I've had to put navigate in a useCallback so it is stable as without that it ends up an infinite render. I can't see any adverse effects this would have?

Screen.Recording.2023-10-13.at.15.51.54.mov

Additional notes

Please tell me if I am being too heavy handed in some of my refactoring! I've taken a few liberties as I thought these changes would make things easier to read and be more consistent. These include:

  • I've renamed and relocated Alerting to AlertingPage. It was in the components folder but it wasn't used elsewhere, so I figured it made sense to rename and relocate it.

  • I've cleaned up the Routing component so that the routes are easier to read. It felt slightly arbitrary that some routes had context providers / PluginPage wrappers in this component vs their own component, so I've moved them all to their own components for consistency.

  • The provisioning global state was only used in routing and it was derived from meta. So I've removed it and I've just pulled meta directly from the context rather than passing it down as a prop.

  • Changing default exports to named exports for consistency. If we end up using webpack chunks for code splitting some things will need to be default exports but that feature isn't used currently.

  • I've started reordering the imports as I was finding them difficult to skim through and find what I was looking for. We could add an eslint rule for this but the order I am aiming for is something like:

  • Node modules

    • react-related things
    • styling-related things
    • grafana-related things
    • everything else
  • Empty line

  • Repo types

  • Context

  • Utilities

  • Hooks

  • Components

I find doing it like this means I can find what I'm looking for. What do you think?

I also noticed that the plugin does have a dependency on Grafana 10 but there are some cases where we are referring to pre-Grafana 10 features (references to topNav feature flag, as one example), are we free to remove them to clean up code or should they be kept?

@ckbedwell ckbedwell requested a review from a team as a code owner October 13, 2023 14:45
@ckbedwell ckbedwell force-pushed the fix/routing-render-bug branch from 269743a to 733e608 Compare October 13, 2023 15:12
@rdubrock
Copy link
Contributor

I also noticed that the plugin does have a dependency on Grafana 10 but there are some cases where we are referring to pre-Grafana 10 features (references to topNav feature flag, as one example), are we free to remove them to clean up code or should they be kept?

It's a bit tricky to decide when to remove them. I think at this point, we've tipped over the point of no longer being backwards compatible. I generally try to stay backwards compatible as long as possible. Up until recently it was compatible back to Grafana v8, but I had some gross dependencies (d3) that I could get rid of by moving to scenes, so I ripped that bandaid off recently.

Copy link
Contributor

@rdubrock rdubrock left a comment

Choose a reason for hiding this comment

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

Nice! Looks great

@rdubrock
Copy link
Contributor

Merge at your leisure!

@ckbedwell ckbedwell merged commit 0be20b5 into main Oct 17, 2023
3 checks passed
@ckbedwell ckbedwell deleted the fix/routing-render-bug branch October 17, 2023 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants