Skip to content

Commit

Permalink
Fix block view scripts being loaded twice (#33406)
Browse files Browse the repository at this point in the history
* Fix block view scripts being loaded twice

* changelog
  • Loading branch information
monsieur-z committed Sep 29, 2023
1 parent 77cb43a commit b3dee29
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
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

0 comments on commit b3dee29

Please sign in to comment.