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

frontend: Fix a circular dependency in KubeObject #2786

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sniok
Copy link
Contributor

@sniok sniok commented Jan 24, 2025

This fixes hot module reloading during development and reenables App.test.tsx

This is a fix for a problem I've been trying to fix for a long time. You might have noticed that during development if you're making any changes the whole page reloads. This is because Hot Module Reload is failing due to a circular dependency. Not every circular dependency causes this kind of failure.

This PR fixes circular dependency: KubeObject -> Router -> All Routes -> The whole app. By reimplementing getDetailsLink and getListLink methods without requiring router. Since routes follow the convention to use apiName, we can take a shortcut and avoid importing and assume the routes follow this convention. The only resources that weren't following this were Storage resources which were updated.

This unfortunately doesn't fix the storybook issue, so that workaround is still there

Signed-off-by: Oleksandr Dubenko <oldubenko@microsoft.com>
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jan 24, 2025
sniok added 3 commits January 24, 2025 13:16
…link methods

Signed-off-by: Oleksandr Dubenko <oldubenko@microsoft.com>
…keKubeObject

Signed-off-by: Oleksandr Dubenko <oldubenko@microsoft.com>
Signed-off-by: Oleksandr Dubenko <oldubenko@microsoft.com>
@sniok sniok force-pushed the kubeobject-circular-dependency-fix branch from 774c556 to 5f01d58 Compare January 24, 2025 12:16
@sniok sniok requested a review from a team January 24, 2025 15:04
path: '/storage/classes',
path: '/storageclasses',
Copy link
Collaborator

Choose a reason for hiding this comment

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

What exactly are these fixing? I think changing a long standing URL may represent a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's inconsistent with the rest of the paths, every other route is using /apiName/:namespace/:name

Comment on lines +128 to +132
const cluster = this.cluster ?? getCluster();
if (this.isNamespaced) {
return `/c/${cluster}/${this._class().apiName}/${params.namespace}/${params.name}`;
}
return `/c/${cluster}/${this._class().apiName}/${params.name}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is replacing a function that produces a full URL by a repetition of the different URL parts a good idea? I'd say these changes make things harder to maintain and more error prone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah in the current form it will make it a bit worse.
but if we take this convention a step further and replace all the routes with:

{
details: {
   path: '/:apiName/:?namespace/:name',
   component: KubeObjectDetails,
},
list: {
  path: '/:apiName/',
  component: KubeObjectList
}
}

I think it will make it less error prone in the long term

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants