-
Notifications
You must be signed in to change notification settings - Fork 22
Remove SVGs from JS bundle, #897
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
Conversation
Use them as `<img>`s. Add alt texts. Remove unnecessary width, height 100% styles. Fixes #498
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 for the bundle size! 👍
💅
Looks like we don't need this SVG mock anymore:
google-listings-and-ads/jest.config.js
Line 23 in c0ecd30
'\\.svg$': '<rootDir>/tests/mocks/assets/svgrMock.js', |
(Just found that the current test did not cover the importing of SVG files, but there is no need to make up then.)
🚧
The archived zip file would not include js/src/
directory.
- I'm not sure if exposing
/js/src/...
as the assets directory is the safest and fits WordPress conventions. At least it does not require moving files around and lets us keep images close to components that use them.
Probably we have to move all SVGs. If keep SVGs at their current positions, it would need to list all SVGs' paths in composer config.
We could consider a solution of centralizing the assets files by below steps:
- Create a
assets
directory at project root - Add
"!/assets"
to the exclude list for including the assets directory into the archived zip file
google-listings-and-ads/composer.json
Lines 62 to 68 in c0ecd30
"archive": { "exclude": [ "!/js/build", "!/vendor/*", "!/languages" ] }, - Replace the
assetsURL
value with$this->get_plugin_url( 'assets/' )
google-listings-and-ads/src/Admin/Admin.php
Lines 111 to 113 in c0ecd30
'glaData', [ 'assetsURL' => plugin_dir_url( $this->get_main_file() ), - Move SVGs to assets directory and then they could be accessed via
/wp-content/plugins/google-listings-and-ads/assets/[filename].svg
path - Run
npm run archive
to see if they're included into zip file as well
Just noticed that the path |
@@ -23,7 +32,14 @@ export const APPEARANCE = { | |||
|
|||
const appearanceDict = { | |||
[ APPEARANCE.GOOGLE ]: { | |||
Logo: GoogleLogo, | |||
Logo: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💅
How about rename to logo
since it's changed to an instantiated component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made me think, that serving an instance is not the best solution as if we are going to create two instances of <AccountCard appearance="google">
, the Logo instance would not be duplicated and appear only in one. Do I get JSX right? I just got used to using HTMLTemplateElement
s and instantiating them, and JSX is not a <template>
;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... 😕 it seems to eventually stamp two separate instances of <img>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 1ead489
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I used an imprecise term. It should be called react element if follow the definitions of React official blog. And the instance should be referred to the component instance in runtime and it keeps references to relevant DOM.
as they are now loaded as images. Addresses #897 (review)
Addresses #897 (review).
Thank you for catching this! 🙏 I'd like to try to keep the files where they are, as it reduced the need for manual syncing assets used by components => reduced the costs and risk of maintaining abandoned files. I decided to try this path.
by adding WDYT about it, does it pass ad blockers you checked? |
I think it's ready for another review. |
💅 |
Sorry, I didn't state that clearly, but my goal was to remove the need of "checking whether a file is still in use" totally. Consider the scenario: It happens that
(our linters will make sure nothing is importing anything from there) As opposed to the solution you propose where
So to me "By declaring SVGs in constants or another dedicated file, and export them directly, the maintenance cost" when removing the component would increase from
Sure, only filenames are required. But in my opinion, additional folder structure gives valuable information. By putting everything to a single flat bag of
I agree. Moreover, this comment might have some sense for a single-use, but repeating it everywhere, and complaining that React does not follow ECMA standards, and produces JS instead of HTML, does not bring any value. I'll remove them. |
as repeatedly complaining that React does not follow ECMA standards, and produces JS instead of HTML, does not bring much value. To partially address #897 (comment)
Addresses #897 (comment).
Another thing to note in favor of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have got @tomalec's perspective from #897 (comment). Considering that the current implementation has already addressed the issue #498, I think there's no blocker for now.
🚧 Sorry, I just noticed that the google-listings-and-ads.zip file should be about the same size as the original, but the reduced file size is almost the same as the index.js. After running google-listings-and-ads/composer.json Line 70 in 55ba670
After deeper investigation about
I haven't look into it but seems the file-loader might be another solution if want to keep images stay with needed components. |
@eason9487 I'm sorry, I missed it again :( |
To add to your investigation Thanks for finding But, given where we are, this seems to be a nice solution for our problem:
The only doubt I have is that we are still on Webpack 4, so we are forced to use something that we now are deprecated and has a cleaner alternative in the future. That kind of introduces additional technical debt. |
Redo #897 Fixes #498 and adds `.scg`s to the `.zip` package #897 (comment)
Changes proposed in this Pull Request:
<img>
s.Fixes #498
Screenshots:
See below
Detailed test instructions:
trunk
andfix/498-svg-out
alt
text is fine.Cases:
Marketing > GLA (Dashboard) > "Edit" Free Listings > step 2
/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fdashboard&subpath=%2Ffree-listings%2Fedit&pageStep=2
Marketing > GLA (Dashboard) > "Add paid campaign" > complete setup

/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fdashboard&guide=campaign-creation-success
Disconnect Google Account using Connection test page
https://gla1.test/wp-admin/admin.php?page=connection-test-admin-page
Marketing > GLA

/wp-admin/admin.php?page=wc-admin&subpath=%2Freconnect-accounts&path=%2Fgoogle%2Fsettings
Disconnect all accounts at
/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fsettings
Marketing > GLA

/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fstart
Complete the setup

/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fproduct-feed&guide=submission-success
Changelog entry
Additional notes:
/js/src/...
as the assets directory is the safest and fits WordPress conventions. At least it does not require moving files around and lets us keep images close to components that use them.index.js
bundle got down by ~52% (719,79KB -> 347.81KB)