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

Found a few issues with navigation guards and fixed them #11190

Merged
merged 1 commit into from
Jun 7, 2024

Conversation

codyrancher
Copy link
Contributor

@codyrancher codyrancher commented Jun 6, 2024

Summary

  • The from/to routes were transposed so I flipped them
  • Load initial settings wasn't receiving the store and the error was swallowed.
  • Fixed some error reporting instead of just swallowing exceptions
  • Removed unnecessary calls to fetchInitialSettings

While working on other changes I noticed that fetchInitialSettings was failing and was being swallowed by the try catch.

Checklist

  • The PR is linked to an issue and the linked issue has a Milestone, or no issue is needed
  • The PR has a Milestone
  • The PR template has been filled out
  • The PR has been self reviewed
  • The PR has a reviewer assigned
  • The PR has automated tests or clear instructions for manual tests and the linked issue has appropriate QA labels, or tests are not needed
  • The PR has reviewed with UX and tested in light and dark mode, or there are no UX changes

- The from/to routes were transposed so I flipped them
- Load initial settings wasn't receiving the store and the error was swallowed.
- Fixed some error reporting instead of just swallowing exceptions
try {
await fetchInitialSettings();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was never actually doing the heavy lifting. All the extra fetchIninitialSettings were actually doing the work. I fixed this and removed the others.

Copy link
Member

Choose a reason for hiding this comment

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

In other words, we previously weren't fetching settings without a reference to the store?

@@ -294,7 +294,7 @@ export async function mountApp(appPartials, VueClass) {
// Push the path and let route to be resolved
router.push(path, undefined, (err) => {
if (err) {
const errorHandler = vueApp.config.errorHandler || console.error; // eslint-disable-line no-console
const errorHandler = vueApp?.config?.errorHandler || console.error; // eslint-disable-line no-console
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've noticed a few times that this is being invoked without vueApp.config being defined.

} catch (ex) {}
await fetchInitialSettings(store);
} catch (e) {
console.error('Failed fetching initial settings', e); // eslint-disable-line no-console
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left this blank because it was a part of the original code but it I accidentally changed the original code and this prevented me from noticing since the error wasn't emitted anywhere.

@codyrancher codyrancher marked this pull request as ready for review June 6, 2024 21:07
@richard-cox richard-cox self-requested a review June 7, 2024 04:58
@codyrancher codyrancher removed the request for review from richard-cox June 7, 2024 16:02
try {
await fetchInitialSettings();
Copy link
Member

Choose a reason for hiding this comment

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

In other words, we previously weren't fetching settings without a reference to the store?

@@ -147,8 +146,6 @@ export default {
// For newer versions this will return all settings if you are somehow logged in,
// and just the public ones if you aren't.
try {
await fetchInitialSettings(this.$store);
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to remove these instances of fetchInitialSettings()? I'm considering if they exist to act as a "refresh" in the event that something might have changed behind the scenes.

Copy link
Contributor Author

@codyrancher codyrancher Jun 7, 2024

Choose a reason for hiding this comment

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

For fetchInitialSettings to act as a refresh instead of using our cache the dispatch methods used from within would need to be passed opt: { force: true }. The second block is also actively skipped if it has ever been fetch since it's looking at generation in the if statement.

Neither dispatch method seems to use this option so I figured that these usages aren't actually refreshing anything. If we'd like to put them back in for comfort I'm fine to do it but the above is why I decided to remove it. Let me know which you'd prefer.

Copy link
Member

Choose a reason for hiding this comment

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

Your explanation helps to quell my fears and I'm not seeing a scenario where removing these instances causes a regression while testing this change. I think that we can leave them out.

Copy link
Member

Choose a reason for hiding this comment

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

@codyrancher @rak-phillip

Settings are a special case. Requests when unauthed will result in a partial response, and when authed the full set.

To resolve this the UI uses load: _MULTI resulting in the response being cached in the store... but not mark as having all results. So any subsequent calls to findAll will still make a http request (without specifying force).

fetchInitialSettings was put in place because we were fetching settings multiple times in different scenarios with the wrong props (resulting in multiple blocking requests on every fresh load).

Given the move of fetching settings outside of the authenticated middlware in #11165 it looks ok to remove these additional ones from brand, setup and login. However we need to validate

  • setup flow works fine
  • no additional settings requests are made (if unauthed 1 then another on log in, or only a single one on load when authed)
  • parts that depends on settings continue to work (for example the brand is correctly applied on setup and logging pages)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@richard-cox thanks for the info. A few questions about the additional testing:

setup flow works fine

  • Are the tests in dashboard/cypress/e2e/tests/setup/rancher-setup.spec.ts sufficient for doing this?

parts that depends on settings continue to work (for example the brand is correctly applied on setup and logging pages)

  • Do you mean something else other than setting up rancher (like in the tests I referenced above) when you say setup?
  • What branding will be available before you've setup rancher? Which logging pages are you referring to?
    • I have already verified that colors and favicons still work on the login page pre auth.

Quick note:
I've just verified that this is working as expected:

no additional settings requests are made (if unauthed 1 then another on log in, or only a single one on load when authed)

Copy link
Member

Choose a reason for hiding this comment

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

Are the tests in dashboard/cypress/e2e/tests/setup/rancher-setup.spec.ts sufficient for doing this?

Good point! I wish whoever put them in remembered he put them in 🤦‍♂️ Apologies for churn.

Do you mean something else other than setting up rancher (like in the tests I referenced above) when you say setup?

Maybe we can skip this one. Branding (/v3/settings/ui-brand) will be applied either at install so will be seen in setup, or once setup in the UI (and setup is not returned to).

What branding will be available before you've setup rancher? Which logging pages are you referring to?

  • I have already verified that colors and favicons still work on the login page pre auth.

That's the one

no additional settings requests are made (if unauthed 1 then another on log in, or only a single one on load when authed)

Perfect.

I think all bases are covered then, and it's really nice removing all those extra calls.

@codyrancher
Copy link
Contributor Author

In other words, we previously weren't fetching settings without a reference to the store?

I don't know why I can't reply inline... This is mostly true, we weren't fetching settings from the intended location. It was getting called from the other locations which I removed in this PR. Those other call sites helped mask the issue that this wasn't getting called properly.

@codyrancher codyrancher merged commit 75ffa34 into rancher:master Jun 7, 2024
34 checks passed
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.

3 participants