Skip to content

CORS Issue and Sub-Collection Caching Problem with Firestore Bundle Builder Extension #25

@rehan-sattar

Description

@rehan-sattar

Hello Team,

We are facing persistent issues with the Firestore Bundle Builder extension and have been unable to resolve them despite multiple attempts and suggestions from Firebase support. Here's a detailed summary of the problems:


1. CORS Issue

When attempting to fetch the bundle using the generateBundle endpoint, we encounter a CORS error:

Error

Access to fetch at 'https://<region>-<project_id>.cloudfunctions.net/ext-firestore-bundle-builder-serve/generateBundle?bundleId=store_products_<storeId>'
from origin 'http://localhost:3000' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
  • We have verified that the Cloud Function region matches the one configured for the extension.
  • The issue persists across various setups, and attempts to work around it (e.g., using a custom proxy function or Firebase Storage) have added unnecessary complexity without fully solving the problem.

2. Sub-Collection Not Being Cached

We need to cache a sub-collection (/stores/{storeId}/products), but the extension does not seem to trigger events for sub-collections, resulting in empty bundles.

  • We confirmed with Firebase support that the extension uses Firestore triggers, and sub-collections are not included unless explicitly configured.
  • We attempted to configure the extension to listen specifically to the path /stores/{storeId}/products, but this did not resolve the issue.
  • Firebase support suggested installing multiple instances of the extension to handle all required collections and sub-collections, but even this approach has not yielded the desired results.

Example Response from generateBundle

{
  "metadata": {
    "id": "store_products_<storeId>",
    "createTime": { "seconds": "1730564593", "nanos": 168900000 },
    "version": 1,
    "totalDocuments": 0,
    "totalBytes": "336"
  },
  "namedQuery": {
    "name": "store_<storeId>_products",
    "bundledQuery": {
      "parent": "projects/<project_id>/databases/(default)/documents",
      "structuredQuery": {
        "from": [
          {
            "collectionId": "firestore.collection('stores').doc('<storeId>').collection('products')"
          }
        ]
      }
    },
    "readTime": { "seconds": "1730564593", "nanos": 168900000 }
  }
}

Despite the sub-collection having many documents, totalDocuments is consistently 0.


Steps Taken

  1. Verified Firestore Security Rules allow read access to /stores/{storeId}/products.
  2. Ensured proper configuration of the extension to listen to sub-collection paths.
  3. Tested alternative methods for fetching bundles (e.g., Firebase Storage, Cloud Function proxies).
  4. Attempted the use of multiple extension instances for caching sub-collections.

Current Status

None of the suggested solutions or troubleshooting steps have resolved the issues. We are unable to proceed with the extension as expected. The inability to cache sub-collections and the persistent CORS error have blocked our implementation entirely.


Request for Assistance

We would greatly appreciate the development team's help in addressing the following:

  1. CORS Issue: Is there a way to enable Access-Control-Allow-Origin headers for the generateBundle endpoint?
  2. Sub-Collection Caching: How can we ensure that sub-collections (e.g., /stores/{storeId}/products) are correctly included in the generated bundles?

Steps to Reproduce

  1. Configure the Firestore Bundle Builder extension to listen to /stores and /stores/{storeId}/products.
  2. Create or modify documents in the /stores/{storeId}/products sub-collection.
  3. Attempt to generate and fetch the bundle using the provided generateBundle endpoint.

We are stuck at this point and unable to move forward. Please let us know how to resolve these issues or if additional details are required.

Thank you for your support!

Best regards,
Rehan Sattar

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions