Skip to content
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

Fix output buffering for cross-origin isolation #65701

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions lib/experimental/media/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@ function gutenberg_rest_get_attachment_filesize( array $post ): ?int {
return null;
}

/**
* Filters the list of rewrite rules formatted for output to an .htaccess file.
*
* Adds support for serving wasm-vips locally.
*
* @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
* @return string Filtered rewrite rules.
*/
function gutenberg_filter_mod_rewrite_rules( string $rules ): string {
$rules .= "\n# BEGIN Gutenberg client-side media processing experiment\n" .
"AddType application/wasm wasm\n" .
"# END Gutenberg client-side media processing experiment\n";

return $rules;
}

add_filter( 'mod_rewrite_rules', 'gutenberg_filter_mod_rewrite_rules' );
swissspidy marked this conversation as resolved.
Show resolved Hide resolved

/**
* Enables cross-origin isolation in the block editor.
*
Expand Down Expand Up @@ -236,16 +254,11 @@ function gutenberg_start_cross_origin_isolation_output_buffer(): void {
$coep = $is_safari ? 'require-corp' : 'credentialless';

ob_start(
function ( string $output, ?int $phase ) use ( $coep ): string {
// Only send the header when the buffer is not being cleaned.
if ( ( $phase & PHP_OUTPUT_HANDLER_CLEAN ) === 0 ) {
Comment on lines -240 to -241
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this is no longer relevant?

I wouldn't have asked if it hadn't been here before, but why was it there before and is now being removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it was there before because I thought I needed it, but turns out it doesn't work, so I just removed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the PL plugin includes this: WordPress/performance#1443

And the Optimization Detective plugin: WordPress/performance#1317

In my testing it worked, although I wrestled with this one for awhile to replicate the scenario where it would be relevant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK what's different here, but this change here fixes the issue for me and would unblock further work, so I'd appreciate an approval

header( 'Cross-Origin-Opener-Policy: same-origin' );
header( "Cross-Origin-Embedder-Policy: $coep" );

$output = gutenberg_add_crossorigin_attributes( $output );
}
function ( string $output ) use ( $coep ): string {
header( 'Cross-Origin-Opener-Policy: same-origin' );
header( "Cross-Origin-Embedder-Policy: $coep" );

return $output;
return gutenberg_add_crossorigin_attributes( $output );
}
);
}
Expand Down
Loading