-
Notifications
You must be signed in to change notification settings - Fork 2
Register runtime as dependency if found #48
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b529e9
Register runtime as dependency if found
mattheu 4eb04d3
Prevent runtime set as dep for CSS
mattheu fa5c7fe
Max comment line length
mattheu 94a3c6c
Line length
mattheu 7ff3ade
Simplify by checking not CSS instead of undoing
mattheu 73528f0
Handle style fallback runtime
mattheu 563332b
Remove duplicate line break
kadamwhite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,10 +107,27 @@ function register_asset( string $manifest_path, string $target_asset, array $opt | |
| $asset_handle = $options['handle'] ?? $target_asset; | ||
| $asset_version = Manifest\get_version( $asset_uri, $manifest_path ); | ||
|
|
||
| // If running the development build with runtimeChunk: single, a runtime file will be present in the manifest. | ||
| // Register this and ensure it is loaded only once per page. | ||
| $runtime = Manifest\get_manifest_resource( $manifest_path, 'runtime.js' ); | ||
| if ( $runtime ) { | ||
| $runtime_handle = 'runtime-' . hash( 'crc32', $runtime ); // Ensure unique handle based on src. | ||
|
mattheu marked this conversation as resolved.
Outdated
|
||
| wp_register_script( $runtime_handle, $runtime ); | ||
| $options['dependencies'][] = $runtime_handle; | ||
| } | ||
|
|
||
| // Track registered handles so we can enqueue the correct assets later. | ||
| $handles = []; | ||
|
|
||
| if ( is_css( $asset_uri ) ) { | ||
| // Don't set runtime JS as dependency of a CSS file. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we call if ( $runtime && ! is_css( $asset_uri ) ) { |
||
| if ( isset( $runtime_handle ) ) { | ||
| $key = array_search( $runtime_handle, $options['dependencies'] ); | ||
| if ( $key !== false ) { | ||
| unset( $options['dependencies'][ $key ] ); | ||
| } | ||
| } | ||
|
|
||
| // Register a normal CSS bundle. | ||
| wp_register_style( | ||
| $asset_handle, | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.