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 block view scripts being loaded twice #33406

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Fix block view scripts being loaded twice
19 changes: 5 additions & 14 deletions projects/plugins/jetpack/tools/webpack.config.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ module.exports = [
context: path.join( __dirname, '../extensions/blocks' ),
noErrorOnMissing: true,
// Automatically link scripts and styles
transform( content, absoluteFrom ) {
transform( content ) {
let metadata = {};

try {
Expand All @@ -212,7 +212,6 @@ module.exports = [
return metadata;
}

const metadataDir = path.dirname( absoluteFrom );
let scriptName = 'editor';

if ( presetIndex.beta.includes( name ) ) {
Expand All @@ -221,23 +220,15 @@ module.exports = [
scriptName += '-experimental';
}

// `editorScript` is required for block.json to be valid and WordPress.org to be able
// to parse it before building the page at https://wordpress.org/plugins/jetpack/.
// Don't add other scripts or styles while block assets are still enqueued manually
// in the backend.
const result = {
...metadata,
editorScript: `file:../${ scriptName }.js`,
editorStyle: `file:../${ scriptName }.css`,
};

if ( fs.existsSync( path.join( metadataDir, 'view.js' ) ) ) {
result.viewScript = 'file:./view.js';
}

if (
fs.existsSync( path.join( metadataDir, 'style.scss' ) ) ||
fs.existsSync( path.join( metadataDir, 'view.scss' ) )
) {
result.style = 'file:./view.css';
}

return JSON.stringify( result, null, 4 );
},
},
Expand Down
Loading