Skip to content

Conversation

dark-panda
Copy link
Contributor

@dark-panda dark-panda commented Mar 18, 2025

This route is sort of duplicated with the root route in the avo-dashboards gem which defines a similarly unused route by default. Having two identically named routes may result in unpredictable behaviour outside of Avo when named routes are being used for things like client-side routing.

Description

Renames the path helpers for the redirect routes /dashboards and /resources.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Manual review steps

This issue was discovered via an edge case scenario where using the js-routes gem (https://github.com/railsware/js-routes) produces invalid JavaScript where the avoDashboardsPath route was being generated twice -- once by the route in config/routes.rb and once in the avo-dashboards gem. This leads to two identically named routes being set up in Rails, which causes two identically named routes to be produced by js-routes. When js-routes produces two identically named constants, it results in an invalid JavaScript file.

To see this behaviour in js-routes:

  1. add the js-routes gem to a Rails application Gemfile
  2. run rake js:routes
  3. check the produced routes.js file for multiple instances of avoDashboardsPath. There should only be one.

Copy link

qlty-cloud-legacy bot commented Mar 18, 2025

Code Climate has analyzed commit 1667d68 and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this PR, @dark-panda!

I've left a suggestion, could you check if it works for your use case?

This approach retains the route with a different path helper method, preventing breaking changes for users who might be relying on the existing route.

Thanks!

config/routes.rb Outdated
@@ -2,7 +2,6 @@
root "home#index"

get "resources", to: redirect(Avo.configuration.root_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
get "resources", to: redirect(Avo.configuration.root_path)
get "resources", to: redirect(Avo.configuration.root_path), as: :avo_resources_redirect
get "dashboards", to: redirect(Avo.configuration.root_path), as: :avo_dashboards_redirect

This route is sort of duplicated with the root route in the
`avo-dashboards` gem which defines a similarly unused route by
default. Having two identically named routes may result in unpredictable
behaviour outside of Avo when named routes are being used for things
like client-side routing.
@dark-panda dark-panda force-pushed the fix-dashboard-routes branch from c4fa34b to 1667d68 Compare March 19, 2025 13:52
@Paul-Bob Paul-Bob changed the title Removes the redirect to the root path for /dashboards refactor: rename /dashboards and /resources redirect path helpers Mar 19, 2025
@Paul-Bob Paul-Bob added Refactor and removed Fix labels Mar 19, 2025
@Paul-Bob Paul-Bob merged commit 759c104 into avo-hq:main Mar 19, 2025
24 of 25 checks passed
@adrianthedev
Copy link
Collaborator

I did not know about that gem @dark-panda.
That will come in handy!
Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants