AdvancedCustomFields / AdvancedCustomFields/acf

JSX parser fails if block contains "{" in data attributes

Open
#707 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Hey,

InnerBlocks are not displayed in the editor if using something like https://alpinejs.dev/ and using inline objects like so:

<div class="block block-accordion" x-data="{ open: false }"></div>
VM2378:1 Uncaught SyntaxError: Expected property name or '}' in JSON at position 1
    at JSON.parse (<anonymous>)
    at q (acf-pro-blocks.min.js?ver=6.0.0-RC2:1:23702)
    at Array.map (<anonymous>)
    at M (acf-pro-blocks.min.js?ver=6.0.0-RC2:1:22706)
    at acf-pro-blocks.min.js?ver=6.0.0-RC2:1:22941
    at Array.forEach (<anonymous>)
    at M (acf-pro-blocks.min.js?ver=6.0.0-RC2:1:22859)
    at acf.parseJSX (acf-pro-blocks.min.js?ver=6.0.0-RC2:1:23888)
    at G.setHtml (acf-pro-blocks.min.js?ver=6.0.0-RC2:1:27202)
    at Object.<anonymous> (acf-pro-blocks.min.js?ver=6.0.0-RC2:1:30079)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the acf.parseJSX entry point and the parsing flow shown in acf-pro-blocks.min.js, then reproduce the issue with the Alpine.js x-data attribute containing { open: false }. Trace why the attribute is passed to JSON.parse and verify that InnerBlocks render correctly without breaking existing JSX parsing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.