Skip to content

Different versions of Firebase in one bundle break the ability to log Timestamp to Firestore #8032

@appsforartists

Description

@appsforartists

Operating System

MacOS 14.3.1 (23D60)

Browser Version

121.0.6167.184 (Official Build) (arm64)

Firebase SDK Version

10.1.0

Firebase SDK Product:

Firestore

Describe your project's tooling

yarn@4.0.1
vite@5.0.12 (esbuild@0.19.5, terser@5.27.2)

Describe the problem

I'm trying to include a timestamp in a log. It works locally, but I see this error when I deploy:

FirebaseError: Function setDoc() called with invalid data. Unsupported field value: a custom pr object (found in field value.creationTime in document experiments/202402-test/meta/info)

Digging into the bundled JS, I realized that Vite (via esbuild) is mangling my names, and that pr is the value it chose for Timestamp. It doesn't appear that Vite allows you to prevent names from being mangled with esbuild, so I tried changing to terser. terser still mangled the name, but it chose at, so now the error is:

FirebaseError: Function setDoc() called with invalid data. Unsupported field value: a custom at object (found in field value.creationTime in document experiments/202402-test/meta/info)

Steps and code to reproduce issue

import {
  getApp,
} from 'firebase/app';

import {
  doc,
  getFirestore,
  setDoc,
  Timestamp,
} from 'firebase/firestore';

const db = getFirestore(getApp());
setDoc(
  doc(db, 'experiments/202402-test/meta/info'),
  {
    value: {
      creationTime: Timestamp.now(),
    }
  },
);

bundled with vite build

Expected result

Firestore should be resilient to common practices like minification.

I can understand the ambiguity around whether {seconds, nanoseconds} should be treated as a Timestamp or an object literal; however, there are solutions. The most correct one is probably to add a special property like "__firebaseBrand__": "Timestamp" and check it to determine how to store/present a value. Alternatively, you could check value.toString().startsWith('Timestamp'), since that class has a custom implementation of toString.

Metadata

Metadata

Assignees

Labels

api: firestorenewA new issue that hasn't be categoirzed as question, bug or feature requestquestion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions