[BUG] objects in script interpolations
Question
Describe the bug (this is not happening in the latest version, this issue is not valid.)
assume that we have a property in our component model which is an object.
then try to interpolate this property in script: what you will get is a [object Object] string.
Steps to reproduce the behavior
- create a custom component type.
- inside model, create a property like this:
test:{a:1,b:2} - inside model, create a script function.
- inside script function, create a variable like this:
const test = '{[ test ]}' - log the parsed value:
console.log(JSON.parse(test)) - an error regarding JSON parsing will be shown.
Expected Behaviour: interpolation of an object property would gives us a JSON string that can be parsed in order to achieve the original object.
Code snippets:
based on the operation in here
we are using JSON.stringify for the array and object types.
so as something like console.log(JSON.parse(JSON.stringify({a:1,b:2}))) is working, we expect the same results here. although we could overcome this scenario by using tagged templates but the way we are transforming script functions into strings, will override the original template literals behavior:
// -- this is not possible inside script --
function template(chunks, ...interpolations) {
console.log(chunks); // ['1 ', ' 3']
console.log(interpolations); // [2]
}
template`1 ${2} 3`;
cheers!
Answers (0)
No answers yet.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #6269
BUG: Component model and view inits every time it's dragged over every component present in Canvas on which it can be dropped into
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Version 130.0.6723.59 (Official Bui...
Issue #4573
BUG: parseStyle is not a function
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Firefox 104.0.1Reproducible demo link https:...
Issue #5990
BUG: When you delete a component, duplicate classes between components will be deleted.
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 126.0.6478.127(Windows) Reproducibl...
Issue #5705
BUG: Component tools misalign when the editor is resized
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v122 Reproducible demo link https:/...
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.