Skip to content

Fix PHP warning for missing runtime.asset.php in production builds#185

Merged
kadamwhite merged 2 commits intodevelopfrom
copilot/fix-missing-runtime-asset-file
Apr 20, 2026
Merged

Fix PHP warning for missing runtime.asset.php in production builds#185
kadamwhite merged 2 commits intodevelopfrom
copilot/fix-missing-runtime-asset-file

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

In production builds, build/runtime.asset.php doesn't exist, but the code unconditionally tried to include it, generating noisy PHP warnings. The HMR runtime file should only be loaded when both the dependency is declared and the file is present.

Changes

  • inc/namespace.php — Reorder and tighten the runtime asset guard in enqueue_assets_for_post:
    1. Check wp-react-refresh-runtime is in the dependency array first (cheap, no I/O)
    2. Verify runtime.asset.php is readable on disk via is_readable() before attempting include
    3. Only then include the file and register the HMR runtime script
// Before — unconditionally includes, warns if file absent
$runtime_asset = include plugin_dir_path( __DIR__ ) . 'build/runtime.asset.php';
if ( ! empty( $runtime_asset ) && in_array( 'wp-react-refresh-runtime', $editor_asset['dependencies'] ?? [], true ) ) {

// After — checks dependency and file existence first
if ( in_array( 'wp-react-refresh-runtime', $editor_asset['dependencies'] ?? [], true ) ) {
    $runtime_asset_file = plugin_dir_path( __DIR__ ) . 'build/runtime.asset.php';
    if ( is_readable( $runtime_asset_file ) ) {
        $runtime_asset = include $runtime_asset_file;
        ...
    }
}

Copilot AI changed the title [WIP] Fix warning on missing runtime asset.php file in production build Fix PHP warning for missing runtime.asset.php in production builds Apr 16, 2026
Copilot AI requested a review from kadamwhite April 16, 2026 21:14
@kadamwhite kadamwhite marked this pull request as ready for review April 20, 2026 17:07
@kadamwhite kadamwhite merged commit 7548a48 into develop Apr 20, 2026
6 checks passed
@kadamwhite kadamwhite deleted the copilot/fix-missing-runtime-asset-file branch April 20, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning on missing runtime asset.php file while using prod build

3 participants