• Resolved coleh

    (@coleh)


    I have a few custom blocks that use Javascript to render data on the front-end. Because of this, I was able to render this data in the block editor with the following code:

    /**
     * Enqueues custom scripts for the block editor.
     */
    function blacklab_block_editor_enqueue()
    {
        wp_register_script('blacklab-scripts', get_template_directory_uri() . '/assets/js/public/blacklab.min.js', array('jquery'), '3.6.6', true);
        wp_localize_script('blacklab-scripts', 'localVar', blacklab_localized_variables());
        wp_enqueue_script('blacklab-scripts');
        wp_enqueue_script('fontawesome', 'https://kit.fontawesome.com/1fd309c3ea.js', '', '', false);
    }
    add_action('enqueue_block_editor_assets', 'blacklab_block_editor_enqueue');

    However, after upgrading to WordPress 5.9, the Javascript no longer executes properly in the block editor. It used to work just fine. I have all my JS combined into one file so I don’t have to separate it out across tons of files for various small blocks. I don’t see anywhere in the notes to mention a change or what is supposed to be done to make this work now.

    The documentation still says to use this:
    https://developer.www.ads-software.com/block-editor/how-to-guides/javascript/loading-javascript/

    Can someone please help me resolve this issue?

    • This topic was modified 3 years, 1 month ago by t-p. Reason: Moved to Fixing WordPress from Alpha/Beta/RC
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator t-p

    (@t-p)

    I don’t see anywhere in the notes to mention a change or what is supposed to be done to make this work now.

    I recommend asking at https://github.com/WordPress/gutenberg/issues

    Thread Starter coleh

    (@coleh)

    I was able to find the issue. It appears the action still does work contrary to what i’ve seen posted saying it was removed.

    Moderator t-p

    (@t-p)

    Glad you got it sorted ??

    Paul Jackson

    (@pixelsandthings)

    @coleh I’m having the exact same issue, what was your solution?

    Thread Starter coleh

    (@coleh)

    @pixelsandthings It has been a while since I resolved it, but it was an error I found in the Chrome debug console with CSS. It was giving an error in the console that once I resolved, the Javascript resolved correctly in the block editor. Unfortunately, I can’t remember remember the exact issue but can confirm the the action still works to load a script in the block editor to run javascript.

    If you need help debugging, feel free to reply and i’ll give give you some contact details.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Scripts no longer work in block editor.’ is closed to new replies.