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

Small dead code removal #10904

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

codyrancher
Copy link
Contributor

@codyrancher codyrancher commented Apr 29, 2024

Summary

Removing bits and pieces of dead code I found while looking through client.js prompted by #10896 (comment)

Areas or cases that should be tested

Mostly around HMR data and fetch invocations.

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

@@ -98,81 +89,6 @@ const errorHandler = Vue.config.errorHandler || console.error; // eslint-disable
// Create and mount App
createApp(nuxt.publicRuntimeConfig).then(mountApp).catch(errorHandler); // eslint-disable-line no-undef

async function loadAsyncComponents(to, from, next) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

// Get matched components
function resolveComponents(route) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After removing other code this was no longer used.

Comment on lines -210 to -218
if (to === from) {
_lastPaths = [];
} else {
const fromMatches = [];

_lastPaths = getMatchedComponents(from, fromMatches).map((Component, i) => {
return compile(from.matched[fromMatches[i]].path)(from.params);
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After removing other code _lastPaths was never read it was only written to.

The risk to removing code in a scenario like this is that a large portion of our code has side effects even in getters. I did look at getMatchedComponents and compile and neither appear to have side effects.

Comment on lines -273 to -277
Components.forEach((Component) => {
if (Component._Ctor && Component._Ctor.options) {
Component.options.fetch = Component._Ctor.options.fetch;
}
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rak-phillip it looks like you were right and we can remove this.

In all the cases I saw when invoking this the method of Component.options.fetch was equal to Component._Ctor.options.fetch so this assignment didn't do anything.

I also verified that HMR was working when modifying code in Project Namespaces.

let instances;

// Call fetch hooks on components matched by the route.
await Promise.all(Components.map((Component, i) => {
Copy link
Contributor Author

@codyrancher codyrancher Apr 30, 2024

Choose a reason for hiding this comment

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

Ultimately this could be removed because we'd exit early from this before doing any mutations. Our fetch method is still called which is obvious by our e2e tests still passing.

@@ -432,52 +265,6 @@ function checkForErrors(app) {
}
}

// When navigating on a different route but the same component is used, Vue.js
// Will not update the instance data, so we have to update $data ourselves
function fixPrepatch(to, ___) {
Copy link
Contributor Author

@codyrancher codyrancher Apr 30, 2024

Choose a reason for hiding this comment

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

We would early exit because _dataRefresh was never true (Because we'd always exit early from the // Call fetch hooks on components matched by the route. section).

This was changing behavior from standard vue and I verified that data was still loading by going to two child routes which shared the same components. More specifically, two list pages which hadn't overridden the default (a few random ones under more resources).

}

function nuxtReady(_app) {
window.onNuxtReadyCbs.forEach((cb) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

onNuxtReadyCbs wenre't being added because there weren't any invocations of onNuxtReady. Without onNuxtReadyCbs this invocation is useless.

}
});
// Special JSDOM
if (typeof window._onNuxtLoaded === 'function') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No usages of _onNuxtLoaded found.

// Initialize error handler
_app.$loading = {}; // To avoid error while _app.$nuxt does not exist
if (NUXT.error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No usages of NUXT.error. It's only scoped to this file.

Comment on lines -499 to -502
Vue.nextTick(() => {
// Call window.{{globals.readyCallback}} callbacks
nuxtReady(_app);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explained why nuxtReady wasn't doing anything in a comment above.

Comment on lines -506 to -510
const Components = await Promise.all(resolveComponents(app.context.route));

if (Components.length) {
_lastPaths = router.currentRoute.matched.map((route) => compile(route.path)(router.currentRoute.params));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

_lastPaths was only written to after other changes.

Comment on lines -533 to -535
if (NUXT.serverRendered && isSamePath(NUXT.routePath, _app.context.route.path)) {
return mount();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No SSR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All changes in this file stemmed from the changes in client.js removing the final use cases of code that was here.

@codyrancher codyrancher added this to the v2.9.0 milestone Apr 30, 2024
@codyrancher codyrancher marked this pull request as ready for review April 30, 2024 16:17
Copy link
Contributor

@cnotv cnotv left a comment

Choose a reason for hiding this comment

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

omg I love this PR

Copy link
Member

@rak-phillip rak-phillip left a comment

Choose a reason for hiding this comment

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

Performed a similar round of testing as in #10896. Looks great!

@codyrancher codyrancher merged commit 9ea4e37 into rancher:master Apr 30, 2024
33 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.

None yet

3 participants