Proof of concept: Codemirror as scriptmodule dep of block editor#68191
Draft
Proof of concept: Codemirror as scriptmodule dep of block editor#68191
Conversation
Co-authored-by: Lena Morita <lena@jaguchi.com>
sirreal
commented
Dec 27, 2024
Comment on lines
+76
to
+94
| $module_deps = array(); | ||
| $script_deps = array(); | ||
| if ( array() !== $deps ) { | ||
| foreach ( $deps as $dep ) { | ||
| if ( is_string( $dep ) ) { | ||
| $script_deps[] = $dep; | ||
| } elseif ( | ||
| isset( $dep['type'], $dep['id'] ) && | ||
| 'module' === $dep['type'] && | ||
| is_string( $dep['id'] ) | ||
| ) { | ||
| $module_deps[] = $dep['id']; | ||
| } | ||
| } | ||
| } | ||
| $script->deps = $script_deps; | ||
| if ( array() !== $module_deps ) { | ||
| $scripts->add_data( $handle, 'module_deps', $module_deps ); | ||
| } |
Member
Author
There was a problem hiding this comment.
This is porting some module dependency changes from WordPress/wordpress-develop#8024.
This was referenced Jun 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Proof of concept and demonstration of WordPress/wordpress-develop#8024 in practice.
Builds on #60155 and using WordPress/wordpress-develop#8024 to add codemirror as an on-demand imported external dependency.
DEWP does not currrently handle these dependencies, so the block editor asset file needs to be manually modified to handle the script module dependencies. After building, change
build/block-editor/index.min.asset.phpto look like this:Why?
Script modules are ideal for deferred or conditional loading of JavaScript assets.
How?
Use the implementation for scripts to depend on script modules proposed in WordPress/wordpress-develop#8024 to load codemirror on demand.
Testing Instructions
Run this along with WordPress/wordpress-develop#8024. Load the editor and add a custom HTML block. In the network tab you'll see that codemirror assets are loaded on demand when the block is added. There are some problems with the block but that's beyond the scope of this proof of concept.
Screenshots or screencast
demo.mov