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

Issue 2393 - Add environment check to Performance Module #3424

Merged
merged 33 commits into from
Aug 18, 2020

Conversation

XuechunHou
Copy link
Contributor

Issue 2393 fix for Performance module.

XuechunHou and others added 20 commits June 2, 2020 11:24
…edDB not supported in some browser situations
…e build (#3156)

* Do not build firestore lite in build because it breaks release build

* add release build script
@changeset-bot
Copy link

changeset-bot bot commented Jul 16, 2020

🦋 Changeset is good to go

Latest commit: f558aa0

We got this.

This PR includes changesets to release 9 packages
Name Type
firebase Minor
@firebase/performance Minor
rxfire Major
@firebase/testing Patch
firebase-browserify-test Patch
firebase-package-typings-test Patch
firebase-messaging-selenium-test Patch
firebase-typescript-test Patch
firebase-webpack-test Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jul 16, 2020

Binary Size Report

Affected SDKs

  • @firebase/analytics

    Type Base (2fa0353) Head (6c05851) Diff
    esm2017 9.66 kB 9.89 kB +229 B (+2.4%)
    main 10.9 kB 11.1 kB +225 B (+2.1%)
    module 10.6 kB 10.8 kB +234 B (+2.2%)
  • @firebase/firestore

    Type Base (2fa0353) Head (6c05851) Diff
    browser 247 kB 249 kB +2.21 kB (+0.9%)
    esm2017 193 kB 195 kB +1.75 kB (+0.9%)
    main 472 kB 475 kB +2.99 kB (+0.6%)
    module 244 kB 247 kB +2.14 kB (+0.9%)
    react-native 193 kB 195 kB +1.73 kB (+0.9%)
  • @firebase/firestore/exp

    Type Base (2fa0353) Head (6c05851) Diff
    browser 187 kB 188 kB +1.71 kB (+0.9%)
    main 464 kB 467 kB +2.94 kB (+0.6%)
    module 187 kB 188 kB +1.71 kB (+0.9%)
    react-native 187 kB 188 kB +1.69 kB (+0.9%)
  • @firebase/firestore/lite

    Type Base (2fa0353) Head (6c05851) Diff
    browser 67.9 kB 64.3 kB -3.56 kB (-5.2%)
    main 144 kB 142 kB -1.37 kB (-1.0%)
    module 67.9 kB 64.3 kB -3.56 kB (-5.2%)
    react-native 67.9 kB 64.4 kB -3.51 kB (-5.2%)
  • @firebase/firestore/memory

    Type Base (2fa0353) Head (6c05851) Diff
    browser 185 kB 187 kB +1.51 kB (+0.8%)
    esm2017 145 kB 146 kB +1.27 kB (+0.9%)
    main 347 kB 349 kB +2.02 kB (+0.6%)
    module 183 kB 185 kB +1.50 kB (+0.8%)
    react-native 145 kB 146 kB +1.26 kB (+0.9%)
  • @firebase/performance

    Type Base (2fa0353) Head (6c05851) Diff
    browser 27.1 kB 27.4 kB +289 B (+1.1%)
    esm2017 25.1 kB 25.4 kB +308 B (+1.2%)
    main 27.1 kB 27.4 kB +289 B (+1.1%)
    module 26.8 kB 27.1 kB +326 B (+1.2%)
  • firebase

    Type Base (2fa0353) Head (6c05851) Diff
    firebase-analytics.js 28.0 kB 28.3 kB +318 B (+1.1%)
    firebase-firestore.js 286 kB 288 kB +2.07 kB (+0.7%)
    firebase-firestore.memory.js 226 kB 227 kB +1.42 kB (+0.6%)
    firebase-performance-standalone.es2017.js 72.1 kB 71.3 kB -822 B (-1.1%)
    firebase-performance-standalone.js 47.4 kB 47.9 kB +549 B (+1.2%)
    firebase-performance.js 37.8 kB 38.3 kB +549 B (+1.5%)
    firebase.js 819 kB 821 kB +2.44 kB (+0.3%)

Test Logs

};
}
interface FirebaseApp {
performance?(): FirebasePerformance;
}
}

async function isSupported(): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Performance is a monitoring sdk. It is easier for the users to initialize it in all environments, but performance will not start internally if all the apis it needs are not available.
Because of that, we probably do not need the isSupported function so the user can check before initializing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Analytics is in a similar situation but it throws if the environment conditions aren't met, on the assumption the developer might want to be alerted if they're not getting analytics data from a certain type of environment. isSupported() is a way to prevent initialization and avoid users having to see those errors. Maybe analytics could make some changes in the future?

But for now, since Performance is designed to surface this through console.info which won't appear for most users, I guess we don't need a mechanism to suppress it. Also performance internal initialization can be blocked by an async check (unlike analytics) so it seems like all the checks and blocking can be handled without developers or users seeing anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the isSupported function

@@ -109,11 +113,30 @@ export class Api {
);
}

requiredApisAvailable(): boolean {
if (fetch && Promise && this.navigator && this.navigator.cookieEnabled) {
async requiredApisAvailable(): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

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

The change looks good!
Can you please add a test for this function as it is not trivial anymore?

Copy link
Contributor

@alikn alikn left a comment

Choose a reason for hiding this comment

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

Thanks a lot, Ida!

stub(FirebaseUtil, 'validateIndexedDBOpenable').throws();
stub(api.navigator, 'cookieEnabled').value(true);
return api.requiredApisAvailable().then(() => {
expect(consoleLogger.info).to.to.be.called;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: one "to" can be removed.

stub(consoleLogger, 'info');
stub(api, 'navigator').value(null);
return api.requiredApisAvailable().then(() => {
expect(consoleLogger.info).to.be.called;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we check for the return value as well?

Copy link
Contributor

@alikn alikn left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks a lot, Ida!

@XuechunHou XuechunHou merged commit 67501b9 into master Aug 18, 2020
@XuechunHou XuechunHou deleted the issue-2393-performance branch August 18, 2020 20:04
@google-oss-bot google-oss-bot mentioned this pull request Aug 18, 2020
@firebase firebase locked and limited conversation to collaborators Sep 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants