Skip to content

Update Webpack chunk generation config#1056

Merged
felixarntz merged 14 commits intodevelopfrom
fix/1054-webpack-chunks
Jan 20, 2020
Merged

Update Webpack chunk generation config#1056
felixarntz merged 14 commits intodevelopfrom
fix/1054-webpack-chunks

Conversation

@aaemnnosttv
Copy link
Copy Markdown
Collaborator

@aaemnnosttv aaemnnosttv commented Jan 17, 2020

Summary

Addresses issue #1054

Relevant technical choices

  • Uses default webpack config for splitChunks
  • commons and vendor chunks are loaded on demand
  • Data localized for sitekit-vendor is still enqueued as a virtual script/dependency
  • Because sitekit-commons is no longer a script which is enqueued, some refactoring was necessary
    • WordPress does not support using wp_add_inline_script for scripts without an src before 5.0, so the initialization of data globals has been replaced with wp_localize_script
      • wp_localize_script is slightly different in that it casts all scalar values of top-level keys to strings. This caused a few E2E tests to fail because a few data request cache keys changed as a result (i.e. false became "" for permaLink). I opted to update the fixtures rather than update the consuming code in several places. In the future, we should nest localized data under a key in the l10n object to prevent this.
      • The other previous inline script for URL runtime polyfill was co-located with others just like it already in place
  • A few E2E endpoints were missing defined methods, which caused failures in older versions of WP until they were added (I'm not sure why as this was working fine before). It was as if the endpoint override wasn't registered.

Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 4.7 and PHP 5.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

tofumatt
tofumatt previously approved these changes Jan 17, 2020
Copy link
Copy Markdown
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

These changes look good to me from a code/config perspective, and simplifying webpack configs is always a 👍🏻thing.

Gonna try this out on a production site but looks good code-wise!

Also:

more-red-than-green

@aaemnnosttv aaemnnosttv marked this pull request as ready for review January 17, 2020 16:49
@felixarntz felixarntz requested a review from swissspidy January 20, 2020 09:37
'window._googlesitekitBase = ' . wp_json_encode( $inline_data ),
'before'
);
wp_localize_script( $handle, '_googlesitekitBase', $this->get_inline_base_data() );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we not leave this to use wp_add_inline_script() instead? This one still has a src, and I'd prefer to use the more proper function wherever possible.

Copy link
Copy Markdown
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Left a comment here about some of the script trickery 😆

$script .
'"></scr\' + \'ipt>\' );'
$script . '?ver=' . GOOGLESITEKIT_VERSION .
'"></scr\' + \'ipt>\' );' . "\n"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's with the split </script> tag here? If it's just a PHPCS security warning we could silence it instead 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because this is a document.write call, not splitting up </script> would actually close the enclosing script tag rather than writing it.

Copy link
Copy Markdown
Collaborator

@tofumatt tofumatt Jan 20, 2020

Choose a reason for hiding this comment

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

Ah, whoops, right. Thanks 😅

(A comment here explaining that might be handy; it's not immediately obvious why that is the way it is 😄)

swissspidy
swissspidy previously approved these changes Jan 20, 2020
@felixarntz felixarntz merged commit ecacfa9 into develop Jan 20, 2020
@felixarntz felixarntz deleted the fix/1054-webpack-chunks branch January 20, 2020 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants