Skip to content

Using Compat-Layer for IndexedDB persistence #3901

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

Closed
wants to merge 1 commit into from

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Oct 6, 2020

This PR pulls the Component Provider from firebase-exp into the legacy SDK. The main challenge is that some of the functionality in FirestoreClient now needs to live in FirebaseFirestore itself (the firestore-exp SDK doesn't use FirestoreClient since it is not tree-shakeable).

This PR passes all tests, but some of the changes here cannot be tested with our current test setup. I verified manually that persistence fallback works and that auth tokens are properly swapped as users sign in and out (by using two users in a web app and enforcing via security rules that each user can only write into their region of Firestore)

@changeset-bot
Copy link

changeset-bot bot commented Oct 6, 2020

⚠️ No Changeset found

Latest commit: 0767aa6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 6, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (79b0493) Head (ffc0b64) Diff
    browser 249 kB 251 kB +2.24 kB (+0.9%)
    esm2017 198 kB 199 kB +1.23 kB (+0.6%)
    main 484 kB 489 kB +4.21 kB (+0.9%)
    module 247 kB 249 kB +2.09 kB (+0.8%)
    react-native 198 kB 199 kB +1.23 kB (+0.6%)
  • @firebase/firestore/exp

    Type Base (79b0493) Head (ffc0b64) Diff
    browser 190 kB 190 kB +16 B (+0.0%)
    main 478 kB 479 kB +283 B (+0.1%)
    module 190 kB 190 kB +16 B (+0.0%)
    react-native 190 kB 190 kB +15 B (+0.0%)
  • @firebase/firestore/lite

    Type Base (79b0493) Head (ffc0b64) Diff
    browser 63.5 kB 63.5 kB -1 B (-0.0%)
    module 63.5 kB 63.5 kB -1 B (-0.0%)
    react-native 63.7 kB 63.7 kB -1 B (-0.0%)
  • @firebase/firestore/memory

    Type Base (79b0493) Head (ffc0b64) Diff
    browser 186 kB 187 kB +1.05 kB (+0.6%)
    esm2017 148 kB 148 kB +215 B (+0.1%)
    main 356 kB 358 kB +1.94 kB (+0.5%)
    module 184 kB 185 kB +914 B (+0.5%)
    react-native 148 kB 148 kB +215 B (+0.1%)
  • firebase

    Type Base (79b0493) Head (ffc0b64) Diff
    firebase-firestore.js 286 kB 288 kB +2.05 kB (+0.7%)
    firebase-firestore.memory.js 225 kB 226 kB +897 B (+0.4%)
    firebase.js 831 kB 833 kB +2.07 kB (+0.2%)

Test Logs

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 6, 2020

Size Analysis Report

Affected Products

No changes between base commit (79b0493) and head commit (ffc0b64).

Test Logs

@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/enablepersistence-compat branch 4 times, most recently from a027964 to 7fc4e46 Compare October 13, 2020 04:38
@schmidt-sebastian schmidt-sebastian changed the title Enable Persistence Compat Using Compat-Layer for IndexedDB persistence Oct 13, 2020
@@ -76,14 +76,29 @@ export interface Settings extends LiteSettings {
cacheSizeBytes?: number;
}

// TODO(firestore-compat): This interface exposes internal APIs that the Compat
// layer implements to interact with the firestore-exp SDL. We can remove this
Copy link
Contributor

Choose a reason for hiding this comment

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

s/SDL/SDK/?

There's a lot of "compat" in this comment but it seems like eventually some of this will be permanent. I wonder if it's worth working toward the future name? Or is "compat" it?

Basically, my concern is that eventually the classic SDK will be fully implemented in terms of the exp SDK and this mechanism of gaining access to internal-only functionality will be permanent. Will this internal-only access always be called "compat"? In iOS and C++ we've called these internal-only extensions "Internal" (e.g. the contents of Firestore/Source/API/Firestore+Internal.h).

What are your thoughts here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The official name for this new API layer is "compat" (I don't like it all that much, but I was told there is precedent across other products). I hope that we can implement the FirestoreCompat layer purely in terms of the tree-shakeable API and that we don't need to keep an internal translation layer. Will see if this pans out.

This specific instance of FirestoreCompat is temporary. The end goal is that all tree-shakeable functions can use the compat APIs and convert to the tree-shakeable types transparently. There is doc here: go/firebase-next-compat

@@ -250,7 +268,7 @@ export function getFirestore(app: FirebaseApp): FirebaseFirestore {
* @return A promise that represents successfully enabling persistent storage.
*/
export function enableIndexedDbPersistence(
firestore: FirebaseFirestore,
firestore: FirestoreCompat,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth nothing somewhere that these function signatures intentionally differ from the public versions in the .d.ts file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They should go back to the public API when once FirebaseFirestore is fully migrated to a compat-style class.

// throws an exception.
this.ensureClientConfigured();
await this._firestoreClient!.terminate();

this._queue.enterRestrictedMode();
Copy link
Contributor

Choose a reason for hiding this comment

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

This and similar changes pulling FirestoreClient code into the API layer seem like a fairly radical departure from the way the other SDKs work.

Notably, on other platforms we have an API layer that serves as a stable interface to user code and we have most of the functionality in places like FirestoreClient. I would expect that even after we transition to tree-shakeable form, we'd still have much of the same structure, except that instead of a FirestoreClient class with methods, it would be a FirestoreClient struct with free functions. Moving this code out of FirestoreClient into the classic API layer seems like the wrong move--this code should end up somewhere in the exp code in the FirestoreClient equivalent over there. If we don't do that, isn't this going to have to be duplicated there?

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 addressed this comment in a new PR and will abandon this one for now: #3974

@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/enablepersistence-compat branch November 9, 2020 22:36
@firebase firebase locked and limited conversation to collaborators Nov 23, 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.

3 participants