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

Circular dependency between base-widget.ts and gridstack.component.ts #2955

Closed
d-luitwieler-anva opened this issue Feb 21, 2025 · 3 comments · Fixed by #2962
Closed

Circular dependency between base-widget.ts and gridstack.component.ts #2955

d-luitwieler-anva opened this issue Feb 21, 2025 · 3 comments · Fixed by #2962
Labels

Comments

@d-luitwieler-anva
Copy link

There is a circular dependency between gridstack.component.ts and base-widget.ts, which in some scenarios will lead to errors. One of those scenario's can be found in the example below where we cannot extend from BaseWidget.
Worth mentioning is that we have other unit tests and other code in the same codebase that extend BaseWidget without any problems.

The issue was discovered in version 11.3.0, but has likely existed long before.

Example.

test-base-widget.spec.ts (jest unit test)

import { BaseWidget } from 'gridstack/dist/angular';

class TestComponent extends BaseWidget {}

it('test', () => {
  // nothing
});

Running this unit test will throw the following error:

Image

We have seen similar weird issues in the past with other code that were eventually tracked down to be caused by Circular Dependencies and often those circular dependencies had existed for a longer period of time, it just never manifested in errors before.

So it is just a matter of time before actual issues occur in other parts of a client's codebase.

@adumesny
Copy link
Member

I see BaseWidget doing
import { NgCompInputs, NgGridStackWidget } from './gridstack.component';
so there is circular, BUT those changes are 21 months old so this isn't new so maybe something else ???

@d-luitwieler-anva
Copy link
Author

We have seen enough circular dependencies in the last few years to know that the order of imports can also matter for either seeing an error or not. So perhaps import changes of any of the dependencies might be the reason the problem never appeared before.

adumesny added a commit to adumesny/gridstack.js that referenced this issue Feb 25, 2025
* fix gridstack#2955
* moves ng types into it's own plain file, fix order of include/export to reflect heirachy
Note: gridComp depends on gridItem but not other way around
@adumesny
Copy link
Member

hopefully fixed in next release...

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 a pull request may close this issue.

2 participants