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

report(psi): stub out locale swapping #13885

Merged
merged 10 commits into from
May 3, 2022
Merged

report(psi): stub out locale swapping #13885

merged 10 commits into from
May 3, 2022

Conversation

paulirish
Copy link
Member

@paulirish paulirish commented Apr 21, 2022

Mostly meant as a recipe for our PSI implementation.

However, we add in these APIs to the report bundle. (and save >100kb by switching the lodash import)
and needed to adopt some of the rollup/fs magic from our other builds to avoid pulling in all the JSON into the build, etc.

const {set: _set, get: _get} = require('lodash');
// Using these rather than the full 'lodash' saves 134kb to the report/bundle.umd.js
const _get = require('lodash.get');
const _set = require('lodash.set');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did it really?

When I reviewed #13695 I checked for this and confirmed that all the extra lodash stuff was getting removed from the bundle.

Copy link
Member Author

@paulirish paulirish Apr 26, 2022

Choose a reason for hiding this comment

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

Did it really?

yup.

image

i noticed this originally after running sourcemapexplorer on the bundle and lodash was so biiiiig.

I also tried moving the two localization/*.js files to esm so the lodash import was esm for treeshaking and i didnt get any savings in that case either.

I did not know about this CVE thing though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not know about this CVE thing though.

also annoying.. the alternatives to lodash's get/set i'm finding don't use the square bracket notation we've been using... eg 'audits[is-on-https].title'. (They just use 'audits.is-on-https.title'). makes migration kinda a pain

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just checked again and confirmed that PR did not change the size, so something else is going on here.

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

But it did change the viewer i18n module:
image

in hindsight none of this lodash changes touched a report, except the i18n stuff, but only for the module/optional report code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah the dt bundle increased in size, which def. uses lodash. oops :(

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

looking at the imported module for lodash...it's a big mess of IIFE so no way treeshaking would work

but i think we can use modules directly: lodash/isEqual.js. I'll try that and maybe open a pr.

Copy link
Collaborator

Choose a reason for hiding this comment

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

* @param {LH.Locale} locale
*/
async function swapLhrLocale(locale) {
const response = await fetch(`https://www.gstatic.com/pagespeed/insights/ui/locales/${locale}.json`);
Copy link
Member

Choose a reason for hiding this comment

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

In the real thing, is the list of locales suggested in the UI generated from the actual locales available so it's not going to 404?

Copy link
Member Author

Choose a reason for hiding this comment

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

ideally, but there's no certainty the locales obj we have matches what's published here. but.. it should.

I think what you may be pointing out is that we should do a lookupLocale if the locale code coming from PSI hasnt already underwent that. At this point, I'm not sure, but i'll find out. Easier to find out once we can try out this PR. :)

@@ -15,3 +15,4 @@ export {DOM} from '../renderer/dom.js';
export {ReportRenderer} from '../renderer/report-renderer.js';
export {ReportUIFeatures} from '../renderer/report-ui-features.js';
export {renderReport} from '../renderer/api.js';
export {swapLocale, format} from '../../shared/localization/i18n-module';
Copy link
Member

Choose a reason for hiding this comment

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

what uses the esm report? I forget, but it uses bundle.js file too so it will have these in there now

Copy link
Member Author

Choose a reason for hiding this comment

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

DevTools uses bundle.esm.js.
(old psi used a psi.js build that was also esm, but that's dead now. new psi uses bundle.umd.js)

Copy link
Collaborator

Choose a reason for hiding this comment

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

so this adds code to the devtool report bundle, when it isn't needed there. should we avoid that?

or should we add swap locale to LH panel :)

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in 68935ef

Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

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

flagging this comment

#13885 (comment)

@paulirish
Copy link
Member Author

flagging this comment

#13885 (comment)

now addressed. @connorjclark ^

// Exclude this 30kb from the devtools bundle for now.
rollupPlugins.shim({
[`${LH_ROOT}/shared/localization/i18n-module.js`]:
'export const swapLocale = _ => {}; export const format = _ => {};',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I guess you need some dummy functions exported here.

@paulirish paulirish merged commit 7528cae into master May 3, 2022
@paulirish paulirish deleted the psiswaplocale branch May 3, 2022 19:26
@connorjclark connorjclark mentioned this pull request May 9, 2022
30 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants