-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
TypeError
since 2.5 when using MIDI controller, caused by deepMerge()
in applyLayer()
#14197
Comments
@christophehenry are you interested in providing a quick fix? I'm afraid I don't have the time to do it myself. |
I'm not sure I am able to provide a fix quickly but I will fix my mess I soon as I can for sure. |
I prepared a quick fix in #14203, just for the case that a simple revert would be acceptable. I cannot evaluate whether this is appropriate, though, and thus marked it as draft. It might also be possible to use Just for the reference:
|
I'm OK with reverting until a better fix is written. This change was here to deprecate Lodash. Removal is not happening any time soon so revert and a fix-release seems to be the best solution.
|
reverting is not an option because using lodash creates loads of warnings. |
I will dig into Lodash's code when I have time to understand what I missed. |
I understand and agree that removing lodash is a worthwile goal. As far as I know, is was deprecated right after release of 2.5 (in current I'm worried about the fact that any quick fix which is not a revert adds a risk of introducing unexpected behavior. |
As I said, |
Thanks for the explanation, I think I understand now. This issue might be an indicator that such a use case for deep merging exists. We will know for sure when the root cause is found and fixed. Hypothesis: If deep merging is not required, |
Yes but we don't know for sure whether someone relies on that deep merging behavior of not. |
@git-developer Can you try after applying the following diff? diff --git a/res/controllers/common-controller-scripts.js b/res/controllers/common-controller-scripts.js
index fcdf516a58..7954ce15f7 100644
--- a/res/controllers/common-controller-scripts.js
+++ b/res/controllers/common-controller-scripts.js
@@ -184,7 +184,16 @@ script.deepMerge = function(target, source) {
isSimpleObject(target[key]) && isSimpleObject(source[key])
) {
deepMerge(target[key], source[key]);
- } else if (source[key] !== undefined && source[key] !== null) {
+ } else if (
+ (
+ source[key] !== undefined &&
+ !(
+ source[key] === source[key] ||
+ (source[key] !== source[key] && source[key] !== source[key])
+ )
+ ) ||
+ (source[key] === undefined && !(key in target))
+ ) {
Object.assign(target, {[key]: source[key]});
}
}); @Swiftb0y I think the problem comes from that Lodash prevents doing useless assignation while |
Thanks for your time and willingness to help. With your patch, the I need some time to investigate. I'l check the difference of the result of |
Thank you both for looking into the issue. Looking forward to a fix. @git-developer, alternatively to relying on |
From a first test:
When using the patch above, the result is empty. The expected result is
|
Thanks for your idea. I have to think about that. The LayerManager is already structured like that, but it's calling A ComponentContainer is prepared to contain Components (obviously) and ComponentContainers. This might be the reason why deep merge is required. applyLayer() performs an optional disconnect, merge, and optional connect, and all 3 tasks are set up to work recursively (because |
@git-developer Dammit I messed up my code replacement. Damn ADHD… I was more careful this time so I hope this next diff works. Can you confirm? diff --git a/res/controllers/common-controller-scripts.js b/res/controllers/common-controller-scripts.js
index fcdf516a58..2a0cdf6493 100644
--- a/res/controllers/common-controller-scripts.js
+++ b/res/controllers/common-controller-scripts.js
@@ -184,7 +184,16 @@ script.deepMerge = function(target, source) {
isSimpleObject(target[key]) && isSimpleObject(source[key])
) {
deepMerge(target[key], source[key]);
- } else if (source[key] !== undefined && source[key] !== null) {
+ } else if (
+ (
+ source[key] !== undefined &&
+ !(
+ target[key] === source[key] ||
+ (target[key] !== target[key] && source[key] !== source[key])
+ )
+ ) ||
+ (source[key] === undefined && !(key in target))
+ ) {
Object.assign(target, {[key]: source[key]});
}
}); |
This patch reintroduces the |
Ok. So I'm lost, here… In a normal situation I'd run the code step by step in the browser, but |
No panic. Instead of changing the recently introduced code with something untested and new, I suggest to revert to lodash for the quick fix. It is known to work properly and thus reduces the risk of defects. We have then more time to fix / refactor the hand-writtten merge algorithm, targeting 2.6. |
In the case of
That assumes all the midi-components mappings still import lodash in 2.5. I'm sure whether thats the case. |
Thanks for this suggestion! Just tried it, and the results of a first test look very good. The I still can't tell for sure if a recursive merge might be required in |
Hmm… Wait, re-reading the code, I notice that we deprecated In the meantime, what I'd do is add a try/catch to Edit: or I could just copy and unfold the code from Lodash so that it fits in a single function. It will be a spaghetti mess but since we want to remove this code eventually, I don't think it's a big deal if it's unreadable and unmaintaintable. |
I see no advantage in keeping |
Maybe not detected due to missing tests? |
Looks like I'm the first and only one who ever called |
almost, yeah 😅 $ grep -Hirn applyLayer
Behringer-Extension-scripts.js:1114: this.activeLayer.applyLayer(this.shiftLayer());
Behringer-Extension-scripts.js:1124: this.activeLayer.applyLayer(this.defaultLayer());
midi-components-0.0.js:522: this.applyLayer(initialLayer);
midi-components-0.0.js:653: applyLayer: function(newLayer, reconnectComponents) {
|
The one usage in |
yeah, I'm just worried about the Behringer stuff. I think those "extension scripts" are used by numerous downstream mappings. |
I don't think so. I'm the author of the
The other Behringer mappings are independent as far as I know. I just made another test. Everything works as expected with |
I restructured the PRs to keep things sorted:
|
Quick fix for #14197 (`TypeError` in `midi-components-0.0.js`)
Quick fix for #14197 (`TypeError` in `midi-components-0.0.js`)
Thanks for merging. |
Bug Description
Problem
The following error is raised since Mixxx 2.5 when using a certain controller mapping:
Analysis
The problem
midi-components-0.0.js
andcommon-controller-scripts.js
are replaced by the revisions of 2.4.midi-components-0.0.js
andcommon-controller-scripts.js
are replaced by the revisions of 2.5.applyLayer()
ofmidi-components-0.0.js
: 2.4 uses_.merge()
(from lodash), 2.5 uses the newly introducesdeepMerge()
function. Reverting this change solves the problem.How to reproduce
Behringer DDM4000.midi.xml
andBehringer-DDM4000-scripts.js
from the attached test case in~/.mixxx/controllers/
[0x90, 0x01]
twice.The attached file deepmerge-issue.log contains a log from this test case.
Additional Details
deepMerge()
change is reverted.read-only property "id"
belongs to a connection object:@christophehenry might be interested.
Version
2.5.0-1~noble
OS
Ubuntu 24.04
The text was updated successfully, but these errors were encountered: