-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proof of concept: Codemirror as scriptmodule dep of block editor #68191
Draft
sirreal
wants to merge
25
commits into
trunk
Choose a base branch
from
add/codemirror-with-script-module-externals
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
Co-authored-by: Lena Morita <[email protected]>
sirreal
added
the
[Type] Technical Prototype
Offers a technical exploration into an idea as an example of what's possible
label
Dec 20, 2024
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 ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is porting some module dependency changes from WordPress/wordpress-develop#8024.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[Type] Technical Prototype
Offers a technical exploration into an idea as an example of what's possible
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.php
to 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