Skip to content

Commit 564cc4d

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents 6cb82e6 + a8b8710 commit 564cc4d

4 files changed

Lines changed: 94 additions & 14 deletions

File tree

src/wp-includes/media.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6608,17 +6608,6 @@ function wp_set_client_side_media_processing_flag(): void {
66086608
if ( null !== $chromium_version && $chromium_version >= 137 ) {
66096609
wp_add_inline_script( 'wp-block-editor', 'window.__documentIsolationPolicy = true;', 'before' );
66106610
}
6611-
6612-
/*
6613-
* Register the @wordpress/vips/worker script module as a dynamic dependency
6614-
* of the wp-upload-media classic script. This ensures it is included in the
6615-
* import map so that the dynamic import() in upload-media.js can resolve it.
6616-
*/
6617-
wp_scripts()->add_data(
6618-
'wp-upload-media',
6619-
'module_dependencies',
6620-
array( '@wordpress/vips/worker' )
6621-
);
66226611
}
66236612

66246613
/**

src/wp-includes/script-modules.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ function wp_default_script_modules() {
211211
wp_interactivity()->add_client_navigation_support_to_script_module( $script_module_id );
212212
}
213213

214-
// VIPS files are always minified — the non-minified versions are not
215-
// shipped because they are ~10MB of inlined WASM with no debugging value.
216-
if ( str_starts_with( $file_name, 'vips/' ) ) {
214+
// VIPS files and the video-conversion worker are always minified — the
215+
// non-minified versions are not shipped because they consist of large
216+
// inlined WASM/worker code with no debugging value.
217+
if ( str_starts_with( $file_name, 'vips/' ) || 'video-conversion/worker.js' === $file_name ) {
217218
$file_name = str_replace( '.js', '.min.js', $file_name );
218219
} elseif ( '' !== $suffix ) {
219220
$file_name = str_replace( '.js', $suffix . '.js', $file_name );

tests/phpunit/tests/media/wpCrossOriginIsolation.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,52 @@ public function test_client_side_processing_enabled_on_localhost() {
315315
);
316316
}
317317

318+
/**
319+
* Verifies that setting the client-side media processing flag does not
320+
* clobber the script module dependencies of the upload-media script.
321+
*
322+
* Re-registering `@wordpress/vips/worker` via WP_Scripts::add_data(),
323+
* which overwrites rather than merges, dropped the module dependencies
324+
* declared in the packages asset file. This removed
325+
* `@wordpress/video-conversion/worker` from the import map and broke
326+
* animated GIF to video conversion.
327+
*
328+
* @ticket 65664
329+
*
330+
* @covers ::wp_set_client_side_media_processing_flag
331+
*/
332+
public function test_set_flag_preserves_upload_media_module_dependencies() {
333+
add_filter( 'wp_client_side_media_processing_enabled', '__return_true' );
334+
335+
$before = wp_scripts()->get_data( 'wp-upload-media', 'module_dependencies' );
336+
337+
wp_set_client_side_media_processing_flag();
338+
339+
$after = wp_scripts()->get_data( 'wp-upload-media', 'module_dependencies' );
340+
341+
$this->assertSame(
342+
$before,
343+
$after,
344+
'The module dependencies of the upload-media script should not be modified.'
345+
);
346+
347+
$ids = array();
348+
foreach ( (array) $after as $module ) {
349+
$ids[] = is_array( $module ) ? $module['id'] : $module;
350+
}
351+
352+
$this->assertContains(
353+
'@wordpress/vips/worker',
354+
$ids,
355+
'The vips worker should be a module dependency of the upload-media script.'
356+
);
357+
$this->assertContains(
358+
'@wordpress/video-conversion/worker',
359+
$ids,
360+
'The video-conversion worker should be a module dependency of the upload-media script.'
361+
);
362+
}
363+
318364
/**
319365
* Verifies that cross-origin elements get crossorigin="anonymous" added.
320366
*

tests/phpunit/tests/script-modules/wpScriptModules.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,50 @@ public function test_default_script_modules() {
18501850
);
18511851
}
18521852

1853+
/**
1854+
* Tests that every default script module points to a file that exists on
1855+
* disk, both with and without SCRIPT_DEBUG.
1856+
*
1857+
* Some files are only shipped minified (large inlined WASM or worker
1858+
* code with no debugging value). Those must be special-cased in
1859+
* wp_default_script_modules() so the non-minified URL is never used;
1860+
* otherwise the import map points to a non-existent file under
1861+
* SCRIPT_DEBUG. The exceptions below must mirror that special case.
1862+
*
1863+
* @ticket 65664
1864+
*
1865+
* @covers ::wp_default_script_modules
1866+
*/
1867+
public function test_default_script_module_files_exist() {
1868+
$assets_file = ABSPATH . WPINC . '/assets/script-modules-packages.php';
1869+
if ( ! file_exists( $assets_file ) ) {
1870+
$this->markTestSkipped( 'The script modules packages asset file is not available.' );
1871+
}
1872+
1873+
$assets = include $assets_file;
1874+
$this->assertNotEmpty( $assets, 'The script modules packages asset file should not be empty.' );
1875+
1876+
foreach ( array_keys( $assets ) as $file_name ) {
1877+
// Files only shipped minified; mirrors wp_default_script_modules().
1878+
if ( str_starts_with( $file_name, 'vips/' ) || 'video-conversion/worker.js' === $file_name ) {
1879+
$file_name = str_replace( '.js', '.min.js', $file_name );
1880+
}
1881+
1882+
$min_file_name = str_ends_with( $file_name, '.min.js' )
1883+
? $file_name
1884+
: substr( $file_name, 0, -3 ) . '.min.js';
1885+
1886+
$this->assertFileExists(
1887+
ABSPATH . WPINC . "/js/dist/script-modules/{$file_name}",
1888+
"The script module file used with SCRIPT_DEBUG enabled should exist for '{$file_name}'."
1889+
);
1890+
$this->assertFileExists(
1891+
ABSPATH . WPINC . "/js/dist/script-modules/{$min_file_name}",
1892+
"The minified script module file should exist for '{$file_name}'."
1893+
);
1894+
}
1895+
}
1896+
18531897
/**
18541898
* Tests expected priority is used when a dependent is registered but not enqueued.
18551899
*

0 commit comments

Comments
 (0)