But if I use $width > instead of $width < the parser chokes on it. Also got errors when using $watch
In the editor the block doesnât work at all when I add Alpine code to the template, even though I import Alpine in editor.js the same way as I do in app.js.
If people are interested in the exact errors let me know.
Yeah, most of my Alpine functionality doesnât need to operate in the editor. Things like sorting posts, opening menus or accordions, etc. I donât really want the editor to be interactive beyond the editing portion.
In general, those are the requirements I work with⌠but that could change depending on the specific use case.
My guess as to the syntax breaking the editor would be that itâs attempting to parse the view as jsx?. Is the supports['jsx'] option for that particular block set to false? Totally spitballing but might be worth a look.
For my case it doesnât make a difference though. Didnât try the editor yet, but I still get this error on the front-end when using > instead of < Uncaught SyntaxError: illegal character U+2018.
Note itâs all fine in a regular blade template.
You both use acf-composer right? Trying to narrow down what the problem is
Not sure what is happening, Iâve tried your code (without x-screen, I donât use that Alpine plugin) and it just works. So maybe the problem is with the plugin.
Maybe you can abstract the code in the x-screen attribute to a function call?
Thanks for helping.
It is weird.
I removed that plugin, then created a standard block with acf-composer, disabled jsx support and added this to the blade template:
Thanks anyway. It is good to know that it should work.
I guess it may have to do with Acorn and/or the fact that I have Acorn installed as a plugin (v2.1.2)
Edit:
Just to be 100% clear: in the snippet < should be replaced with > to produce the error. Also the above block works for me in the editor (when disabling jsx, so thanks for that), the error occurs on the front-end.
I went through this a year ago, it has to do with ACFâs parsing of the view when using JSX, nothing to do with Acorn. To fix you need to wrap anything with âillegalâ characters with esc_attr when enabling JSX. Or move the JS to a file and just call the function from x-data, x-init, etc.
Thanks! Is still donât know why I get these errors in my basic example with jsx disabled (and joshf not). But I can confirm wrapping with esc_atrr does work (also with my non-jsx example).
/**
* Converts the given attribute into a React friendly name and value object.
*
* @date 19/05/2020
* @since 5.9.0
*
* @param obj nodeAttr The node attribute.
* @return obj
*/
function parseNodeAttr(nodeAttr) {
let name = nodeAttr.name;
let value = nodeAttr.value;
// Allow overrides for third party libraries who might use specific attributes.
let shortcut = acf.applyFilters('acf_blocks_parse_node_attr', false, nodeAttr);
if (shortcut) return shortcut;
switch (name) {
// Class.
case 'class':
name = 'className';
break;
// Style.
case 'style':
const css = {};
value.split(';').forEach(s => {
const pos = s.indexOf(':');
if (pos > 0) {
let ruleName = s.substr(0, pos).trim();
const ruleValue = s.substr(pos + 1).trim();
// Rename core properties, but not CSS variables.
if (ruleName.charAt(0) !== '-') {
ruleName = acf.strCamelCase(ruleName);
}
css[ruleName] = ruleValue;
}
});
value = css;
break;
// Default.
default:
// No formatting needed for "data-x" attributes.
if (name.indexOf('data-') === 0) {
break;
}
// Replace names for JSX counterparts.
name = getJSXName(name);
// Convert JSON values.
const c1 = value.charAt(0);
if (c1 === '[' || c1 === '{') {
value = JSON.parse(value);
}
// Convert bool values.
if (value === 'true' || value === 'false') {
value = value === 'true';
}
break;
}
return {
name,
value
};
}