Title: [Bug] Uncaught SyntaxError: &#8216;jtoc_data_all&#8217;
Last modified: June 1, 2026

---

# [Bug] Uncaught SyntaxError: ‘jtoc_data_all’

 *  [hassan](https://wordpress.org/support/users/sangshenas/)
 * (@sangshenas)
 * [1 week, 3 days ago](https://wordpress.org/support/topic/bug-uncaught-syntaxerror-jtoc_data_all/)
 * **Environment**
    - WordPress version: (6.9.4)
    - Plugin version: (3.0.2)
    - Browser: (chrome lastest)
    - Conflicting plugins: (WP Rocket)
 * **Description**
 * When opening the Block Editor (Gutenberg) to edit a post, the following JavaScript
   error appears in the browser console:
 *     ```wp-block-code
       Uncaught SyntaxError: Identifier 'jtoc_data_all' has already been declared
       (at post.php?post=XXXXX&action=edit:41204:11)
       ```
   
 * **Root Cause**
 * The variable `jtoc_data_all` is declared using `let` or `const`, which does not
   allow re-declaration in the same scope. When the plugin’s script is enqueued 
   or rendered more than once on the editor page — likely due to a caching/optimization
   plugin combining or deferring scripts — the browser throws a SyntaxError on the
   duplicate declaration.
 * **Steps to Reproduce**
    1. Install and activate Joli Table of Contents (latest version).
    2. Open any post in the Block Editor (post.php?action=edit).
    3. Open the browser DevTools console.
    4. Observe the SyntaxError.
 * **Expected Behavior**
 * No JavaScript errors in the console. The script should be loaded only once, and
   the variable declaration should be guarded against duplicate execution.
 * **Actual Behavior**
 * A SyntaxError is thrown because `jtoc_data_all` is declared twice with `let`/`
   const` in the same scope.
 * **Impact**
    - The error only appears in the admin editor; the front-end TOC rendering is
      not affected.
    - However, the duplicate declaration could potentially block subsequent scripts
      from executing in certain environments.
 * **Suggested Fix**
 * Guard the variable declaration to prevent re-declaration:
 *     ```wp-block-code
       // Instead of:
       let jtoc_data_all = ...;
   
       // Use:
       if (typeof jtoc_data_all === 'undefined') {
           var jtoc_data_all = ...;
       }
       ```
   
 * Alternatively, ensure the script is registered and enqueued only once on the 
   editor page using `wp_enqueue_script()` with a unique handle and proper dependency
   management.
 * Thank you for looking into this!

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fbug-uncaught-syntaxerror-jtoc_data_all%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/joli-table-of-contents/assets/icon-256x256.png?rev=3487088)
 * [Joli Table Of Contents](https://wordpress.org/plugins/joli-table-of-contents/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/joli-table-of-contents/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/joli-table-of-contents/)
 * [Active Topics](https://wordpress.org/support/plugin/joli-table-of-contents/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/joli-table-of-contents/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/joli-table-of-contents/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [hassan](https://wordpress.org/support/users/sangshenas/)
 * Last activity: [1 week, 3 days ago](https://wordpress.org/support/topic/bug-uncaught-syntaxerror-jtoc_data_all/)
 * Status: not resolved