Skip to content

[FEAT] Restrict Firestore Doc/QuerySnapshot toJSON on client. #9048

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

Merged

Conversation

DellaBitta
Copy link
Contributor

@DellaBitta DellaBitta commented May 15, 2025

Discussion

To reduce bundle size on clients, the toJSON methods of DocumentSnapshot and QuerySnapshot will not create bundles.

Testing

Updated the integration and unit tests to test fromJSON functionality in node environments only.

I did attempt to create pre-packaged bundles so that we can test in browser still, but unforunately the bundle includes the project name, and the project that we test against varies depending on the profile of tests that were running (prod, local, etc). If these don't match then an error is thrown.

API Changes

N/A

Copy link

changeset-bot bot commented May 15, 2025

⚠️ No Changeset found

Latest commit: 158b491

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

Copy link
Contributor

Vertex AI Mock Responses Check ⚠️

A newer major version of the mock responses for Vertex AI unit tests is available. update_vertexai_responses.sh should be updated to clone the latest version of the responses: v13.0

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 15, 2025

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (a49774f)Merge (517f865)Diff
    browser399 kB395 kB-4.23 kB (-1.1%)
    main615 kB615 kB+756 B (+0.1%)
    module399 kB395 kB-4.23 kB (-1.1%)
    react-native399 kB395 kB-4.23 kB (-1.1%)
  • bundle

    TypeBase (a49774f)Merge (517f865)Diff
    firestore (CSI Auto Indexing Disable and Delete)298 kB290 kB-8.16 kB (-2.7%)
    firestore (CSI Auto Indexing Enable)298 kB290 kB-8.16 kB (-2.7%)
    firestore (Persistence)329 kB321 kB-7.96 kB (-2.4%)
    firestore (Query Cursors)264 kB260 kB-3.92 kB (-1.5%)
    firestore (Query)261 kB258 kB-3.92 kB (-1.5%)
    firestore (Read data once)255 kB247 kB-8.07 kB (-3.2%)
    firestore (Read Write w Persistence)345 kB341 kB-3.87 kB (-1.1%)
    firestore (Realtime updates)256 kB248 kB-8.07 kB (-3.2%)
    firestore (Transaction)232 kB226 kB-6.05 kB (-2.6%)
    firestore (Write data)233 kB227 kB-6.05 kB (-2.6%)
  • firebase

    TypeBase (a49774f)Merge (517f865)Diff
    firebase-compat.js810 kB806 kB-3.83 kB (-0.5%)
    firebase-firestore-compat.js354 kB350 kB-3.83 kB (-1.1%)
    firebase-firestore.js462 kB458 kB-4.24 kB (-0.9%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/iVe0uo2m7s.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 15, 2025

Size Analysis Report 1

This report is too large (1,806,337 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/01mFgoykek.html

Base automatically changed from ddb-sync-bundle-parse to ddb-firestore-result-serialization May 16, 2025 14:11
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result: any = {};
result['type'] = QuerySnapshot._jsonSchemaVersion;
result['bundleSource'] = 'QuerySnapshot';
result['bundleName'] = AutoId.newId();

const builder: BundleBuilder = new BundleBuilder(
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 bundle code is now moved into a platform specific file so only for node environments. The other platforms produce a bundle string that simply reads NOT SUPPORTED.

@DellaBitta DellaBitta requested a review from MarkDuckworth May 19, 2025 13:52
@DellaBitta DellaBitta marked this pull request as ready for review May 19, 2025 13:52
@DellaBitta DellaBitta requested review from a team as code owners May 19, 2025 13:52
Copy link
Contributor

@MarkDuckworth MarkDuckworth left a comment

Choose a reason for hiding this comment

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

This is great!

@DellaBitta DellaBitta merged commit 38d8bc5 into ddb-firestore-result-serialization May 19, 2025
78 of 85 checks passed
@DellaBitta DellaBitta deleted the ddb-no-client-origin-bundles branch May 19, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants