Media: Fix animated GIF to video conversion failing due to missing import map entry#12598
Media: Fix animated GIF to video conversion failing due to missing import map entry#12598adamsilverstein wants to merge 4 commits into
Conversation
wp_set_client_side_media_processing_flag() re-registered @wordpress/vips/worker as a module dependency of the wp-upload-media script on every admin request. WP_Scripts::add_data() overwrites rather than merges, so this dropped the other dependencies declared in script-loader-packages.php - notably @wordpress/video-conversion/worker, which was added there after this call was introduced. With that entry missing from the import map, import( '@wordpress/video-conversion/worker' ) throws and animated GIFs never get their companion video. The packages asset file already registers both workers when the script is registered, so the call can simply be removed.
…_DEBUG The Gutenberg build only ships video-conversion/worker.min.js: like the VIPS modules, the unminified worker is large inlined code with no debugging value, so it is not produced at all. wp_default_script_modules() only special-cased vips/ for this, so with SCRIPT_DEBUG enabled the import map pointed at the non-existent worker.js and the dynamic import failed with a 404, breaking animated GIF to video conversion in development environments.
The first test guards against wp_set_client_side_media_processing_flag() modifying the upload-media script's module dependencies again: add_data() overwrites rather than merges, which is how the video-conversion worker silently dropped out of the import map. The second test verifies that every default script module resolves to a file that exists on disk for both SCRIPT_DEBUG variants, so a module that is only shipped minified cannot be registered with a non-existent non-minified URL without failing the suite. See #65664.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
andrewserong
left a comment
There was a problem hiding this comment.
Good catch! This is testing nicely for me on a local checkout, thanks for the explanations in the PR description 👍
Adding the video-conversion worker to the list in script-modules.php makes sense for now. I suppose if we ever grow this list we could abstract the concept somehow, but for the scope of client-side media processing I doubt we'll ever really have more than vips + video-conversion? And if we do want to proposed more worker / skipping non-minified build features, then I reckon we could revisit then.
LGTM!
What
Fixes animated GIF to video conversion, which currently fails silently everywhere client-side media processing runs (block editor included): no
animated_videocompanion is created, and the console shows:Why
Two separate bugs prevent
upload-media.jsfrom lazily importing the conversion worker:wp_set_client_side_media_processing_flag()clobbers the import map. It callswp_scripts()->add_data( 'wp-upload-media', 'module_dependencies', array( '@wordpress/vips/worker' ) )on every admin request.add_data()overwrites rather than merges, wiping themodule_dependenciesalready registered fromscript-loader-packages.php- which include both@wordpress/vips/workerand@wordpress/video-conversion/worker. The call was harmlessly redundant when introduced in [62428] (the packages file only declared the vips worker then) and became destructive when the video-conversion dependency landed in the asset file. With the entry missing from the import map, the dynamicimport()throws. Since the packages registration already handles this correctly, the call is simply removed.The unminified
video-conversion/worker.jsis never shipped. Like the VIPS modules, the Gutenberg build only producesworker.min.js(the file is large inlined worker code with no debugging value), butwp_default_script_modules()only special-casesvips/to always use the minified file. WithSCRIPT_DEBUGenabled, the import map pointed at a non-existentworker.jsand the import 404ed. The existing vips condition is extended to covervideo-conversion/worker.js.Testing
Manually verified on trunk (Chrome, cross-origin isolated via Document-Isolation-Policy):
Before: uploading an animated GIF logs the module-specifier
TypeError(plus a secondaryblob: ... ERR_FILE_NOT_FOUNDerror), and the attachment'smedia_detailshas noanimated_video.After: the same upload completes with no console errors, the import map contains both workers, and the attachment gains
animated_video: <name>.mp4andanimated_video_poster: <name>.jpeg, with both companion files sideloaded to the uploads directory.Includes PHPUnit coverage (
--group 65664):test_set_flag_preserves_upload_media_module_dependencies()assertswp_set_client_side_media_processing_flag()leaves the upload-media script'smodule_dependenciesuntouched and that both workers are present. Verified to fail against the pre-fix code (the dependency list collapses to just the vips worker) and pass with the fix.test_default_script_module_files_exist()asserts every default script module resolves to an existing file for bothSCRIPT_DEBUGvariants, so a minified-only module can no longer be registered with a non-existent non-minified URL.Both full test files pass (25 + 108 tests);
php -land PHPCS pass on all changed files.Commit message
Trac ticket: https://core.trac.wordpress.org/ticket/65664