BUG: Trait add/remove can fail because collection type is inconsistent
Question
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Brave Version 1.31.88 Chromium: 95.0.4638.69 (Official Build) (64-bit) on Linux
Reproducible demo link
https://jsfiddle.net/0a3o7cL6/
Describe the bug
Methods which operate on a component's trait collection (e.g. addTrait and removeTrait) seem to always assume the collection will be the Backbone-derived collection type, however there are cases where it's a simple Array instead. The code then attempts to call methods which don't exist.
I'm not familiar enough with the codebase to say for certain whether the actual bug is get('traits') returning the inconsistent type or the calling methods not accounting for the mixed return type. I discovered this behavior in the Video component, which has its runtime trait overwriting, I'm unsure if any other components are affected.
The JSFiddle is basically taken from: https://github.com/artf/grapesjs/issues/1999
How to reproduce the bug?
- Add a call which adds a trait to a component (in
initor another callback) which has an unreliable trait collection type (Video confirmed) - Attempt to create an instance of that component
What is the expected behavior?
addTrait should not explode
What is the current behavior?
Uncaught TypeError: this.get(...).add is not a function
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (1)
Yeah, I'll fix it in the next release, thanks
Related Questions and Answers
Continue research with similar issue discussions.
Issue #4323
BUG: Performance issue while dragging component to canvas when you have 2k component on canvas
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Google Chrome Version 101.0.4951.41 (Officia...
Issue #5173
BUG: editor.Css.setRule API not working as expected, it is not updating the rule existing rule.
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 112.0.5615.137 (Official Build) (a...
Issue #5112
BUG: GrapeJS/drag and drop not working for Brave on Linux and Wayland
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 1.51.110 Chromium: 113.0.5672.77 (...
Issue #5718
BUG: Possible upgrade path issue where 'textnode' is now called 'wrapper' from 0.18 -> latest
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Version 122.0.6261.95 (Official Bui...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.