Describe the bug
When I tried to doc.set or doc.get an object that has a list of DocumentReference inside it
I got an error :
Uncaught (in promise) Error: [cloud_firestore/unknown] Invalid argument: Maximum call stack size exceeded
errors.dart:167 Uncaught (in promise) Error: [cloud_firestore/unknown] Invalid argument: Maximum call stack size exceeded
at Object.throw_ [as throw] (errors.dart:216)
at document_reference_web.DocumentReferenceWeb.new.get (document_reference_web.dart:56)
at get.next (<anonymous>)
at async_patch.dart:45
at _RootZone.runUnary (zone.dart:1450)
at _FutureListener.thenAwait.handleValue (future_impl.dart:143)
at handleValueCallback (future_impl.dart:696)
at Function._propagateToListeners (future_impl.dart:725)
at _Future.new.[_completeWithValue] (future_impl.dart:529)
at async._AsyncCallbackEntry.new.callback (future_impl.dart:567)
at Object._microtaskLoop (schedule_microtask.dart:41)
at _startMicrotaskLoop (schedule_microtask.dart:50)
at async_patch.dart:166
Click To Expand
[✓] Flutter (Channel beta, 1.23.0-18.1.pre, on Linux, locale en_IN.utf8)
• Flutter version 1.23.0-18.1.pre at /opt/flutter
• Framework revision 198df796aa (4 weeks ago), 2020-10-15 12:04:33 -0700
• Engine revision 1d12d82d9c
• Dart version 2.11.0 (build 2.11.0-213.1.beta)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /home/rot/Android/Sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio
• Android Studio at /opt/android-studio
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] Connected device (1 available)
• Web Server (web) • web-server • web-javascript • Flutter Tools
! Doctor found issues in 1 category.```
</details>
---
### Flutter dependencies
Run `flutter pub deps -- --style=compact` and paste the output below:
<details><summary>Click To Expand</summary>
dependencies:
dev dependencies:
transitive dependencies:
I'm also facing the exact same issue right now.
Hi @bhanugummana @muhammad-curate
Could you be facing this due to https://github.com/flutter/flutter/issues/66122? That was fixed on master so could you try switching to the latest flutter master?
Thank you
@markusaksli-nc updated to master still facing the same issue. Thank you
Click To Expand
```Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.24.0-8.0.pre.208, on Linux, locale en_IN.utf8)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio
[✓] Connected device (1 available)
! Doctor found issues in 1 category.```
Same result as well. Switching to master channel has the same issue for me.
@bhanugummana Could you please provide a minimal complete reproducible code sample for your exact setup of this
doc.set or doc.get an object that has a list of DocumentReference inside it
@markusaksli-nc sample code to reproduce the issue
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Center(
child: MaterialButton(
child: Text("click here"),
onPressed: () async {
//setting an object that has a list of DocumentReference inside it
var map = {
"name": "test",
"ref": [
FirebaseFirestore.instance.doc('class/zxcvbnm'),
FirebaseFirestore.instance.doc('class/asdfghj')
]
};
await FirebaseFirestore.instance
.collection('test')
.doc()
.set(map)
.catchError(
(error) {
print(
error); // error Error: [cloud_firestore/unknown] Invalid argument (dartObject): Could not convert: Instance of 'DocumentReference'
},
);
//getting an object that has a list of DocumentReference inside it
await FirebaseFirestore.instance
.collection('test')
.doc('zxcvbnm')
.get()
.catchError(
(error) {
print(
error); //js_primitives.dart:30 [cloud_firestore/unknown] Invalid argument: Maximum call stack size exceeded
},
);
},
),
),
);
}
}
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>
dependencies:
firebase_core: ^0.5.2
cloud_firestore: ^0.14.3
Reproducible on latest flutter 1.24.0-8.0.pre.229 master with cloud_firestore: ^0.14.3 (on web but not on Android).
flutter doctor -v
[√] Flutter (Channel master, 1.24.0-8.0.pre.229, on Microsoft Windows [Version 10.0.19041.572], locale et-EE)
• Flutter version 1.24.0-8.0.pre.229 at C:\Development\flutter_master
• Framework revision 7cda6866b0 (10 hours ago), 2020-11-12 22:39:02 -0500
• Engine revision dddb532b5c
• Dart version 2.12.0 (build 2.12.0-37.0.dev)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\marku\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.7)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.7.30621.155
• Windows 10 SDK version 10.0.18362.0
[√] Android Studio (version 4.1.0)
• Android Studio at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] IntelliJ IDEA Ultimate Edition (version 2020.2)
• IntelliJ at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\202.7660.26
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
[√] Connected device (6 available)
• SM G950F (mobile) • ce12171c51cc001c03 • android-arm64 • Android 9 (API 28)
• sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19041.572]
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome 86.0.4240.193
• Edge (web) • edge • web-javascript • Microsoft Edge 86.0.622.68
• No issues found!
I edited your sample a bit to make it easier to test.
Minimal reproducible code sample
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("DocumentReference example"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
RaisedButton(
child: const Text("Set test docs for refs"),
onPressed: () {
var mapA = {
"name": "refA",
};
var mapB = {
"name": "refB",
};
FirebaseFirestore.instance
.collection('test')
.doc('testA')
.set(mapA)
.catchError(
(error) {
print(error);
},
);
FirebaseFirestore.instance
.collection('test')
.doc('testB')
.set(mapB)
.catchError(
(error) {
print(error);
},
);
},
),
RaisedButton(
child: const Text("Set doc with ref"),
onPressed: () async {
//works on web
//setting an object that has a DocumentReference inside it
var map = {
"name": "test",
"ref": FirebaseFirestore.instance.doc("/test/refA")
};
await FirebaseFirestore.instance
.collection('test')
.doc('testDoc')
.set(map)
.catchError(
(error) {
print(error);
},
);
},
),
RaisedButton(
child: const Text("Set doc with ref list"),
onPressed: () async {
//doesnt work on web
//setting an object that has a list of DocumentReferences inside it
var map = {
"name": "test",
"ref": [
FirebaseFirestore.instance.doc("/test/refA"),
FirebaseFirestore.instance.doc("/test/refB")
]
};
await FirebaseFirestore.instance
.collection('test')
.doc('testDoc')
.set(map)
.catchError(
(error) {
// error Error: [cloud_firestore/unknown] Invalid argument (dartObject): Could not convert: Instance of 'DocumentReference'
print(error);
},
);
},
),
RaisedButton(
child: const Text("Get doc"),
onPressed: () async {
var doc = await FirebaseFirestore.instance
.collection('test')
.doc('testDoc')
.get()
.catchError(
(error) {
//js_primitives.dart:30 [cloud_firestore/unknown] Invalid argument: Maximum call stack size exceeded
print(error);
},
);
print(doc.get("ref"));
},
),
],
),
),
),
);
}
}
Logs
[+5259 ms] [cloud_firestore/unknown] Invalid argument: Maximum call stack size exceeded
[ +1 ms] TypeError: Cannot read property 'get' of undefined
at http://localhost:49734/packages/triage/main.dart.lib.js:639:36
at Generator.next (<anonymous>)
at http://localhost:49734/dart_sdk.js:37958:33
at _RootZone.runUnary (http://localhost:49734/dart_sdk.js:37812:58)
at _FutureListener.thenAwait.handleValue (http://localhost:49734/dart_sdk.js:32773:29)
at handleValueCallback (http://localhost:49734/dart_sdk.js:33321:49)
at Function._propagateToListeners (http://localhost:49734/dart_sdk.js:33359:17)
at _Future.new.[_completeWithValue] (http://localhost:49734/dart_sdk.js:33201:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:49734/dart_sdk.js:33224:35)
at Object._microtaskLoop (http://localhost:49734/dart_sdk.js:38073:13)
at _startMicrotaskLoop (http://localhost:49734/dart_sdk.js:38079:13)
at http://localhost:49734/dart_sdk.js:33576:9
...
[+49160 ms] [cloud_firestore/unknown] Invalid argument (dartObject): Could not convert: Instance of 'DocumentReference'
@markusaksli-nc Are you sure this is an issue with DocumentReference list?
Because we see Invalid argument: Maximum call stack size exceeded in one project that does it and also see it in another project that does not use it.
The sample I provided seems to show that is an issue with a DocumentReference list specifically. There were other issues with js object list conversions on web (see https://github.com/FirebaseExtended/flutterfire/issues/4063). Not sure if it is fixed yet since as far as I know that PR hasn't rolled into a plugin version bump yet.
What other case specifically are you referring to?
@markusaksli-nc Nevermind, were able to fix it :)
Until https://github.com/FirebaseExtended/flutterfire/pull/4212 (fix PR) is merged, you can use the following dependencies:
dependency_overrides:
firebase_core_web:
git:
url: https://github.com/simpleclub-extended/flutterfire
ref: fix-document-reference-check
path: packages/firebase_core/firebase_core_web
cloud_firestore_web:
git:
url: https://github.com/simpleclub-extended/flutterfire
ref: fix-document-reference-check
path: packages/cloud_firestore/cloud_firestore_web
Most helpful comment
Reproducible on latest flutter
1.24.0-8.0.pre.229master withcloud_firestore: ^0.14.3(on web but not on Android).flutter doctor -v
I edited your sample a bit to make it easier to test.
Minimal reproducible code sample
Logs