Flutterfire: 🐛 [cloud_firestore_web] Can't get or set document with DocumentReference list

Created on 12 Nov 2020  ·  10Comments  ·  Source: FirebaseExtended/flutterfire

Bug report

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

Full error

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

Flutter doctor

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:

  • cached_network_image 2.3.3 [flutter flutter_cache_manager octo_image]
  • camera 0.5.8+11 [flutter]
  • chewie 0.9.10 [open_iconic_flutter video_player wakelock flutter]
  • cloud_firestore 0.14.3 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web]
  • country_code_picker 1.6.2 [flutter modal_bottom_sheet]
  • cupertino_icons 0.1.3
  • double_back_to_close_app 1.2.0 [flutter]
  • email_validator 1.0.6
  • extended_image 0.9.0 [flutter extended_image_library]
  • firebase 7.3.2 [http http_parser js]
  • firebase_analytics 6.2.0 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface]
  • firebase_auth 0.18.3 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter]
  • firebase_core 0.5.2 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
  • firebase_storage 4.0.1 [flutter firebase_core]
  • flare_dart 2.3.4
  • flare_flutter 1.8.3 [flutter flare_dart]
  • flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
  • flutter_local_notifications 1.5.0+1 [flutter platform flutter_local_notifications_platform_interface]
  • flutter_localizations 0.0.0 [flutter intl characters collection meta path typed_data vector_math]
  • flutter_offline 0.3.0 [flutter connectivity]
  • flutter_phoenix 0.1.0 [flutter]
  • flutter_sim_country_code 0.0.3 [flutter]
  • google_sign_in 4.5.6 [google_sign_in_platform_interface flutter meta google_sign_in_web]
  • image 2.1.18 [archive xml meta]
  • image_picker 0.6.7+14 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
  • md2_tab_indicator 1.0.2 [flutter]
  • mockito 4.1.3 [analyzer build code_builder collection dart_style matcher meta source_gen test_api]
  • otp_text_field 1.0.1 [flutter]
  • parse_server_sdk 1.0.26 [http flutter web_socket_channel sembast xxtea shared_preferences path_provider uuid package_info devicelocale meta path]
  • path_provider 1.6.24 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
  • progress_dialog 1.2.4 [flutter]
  • provider 4.3.2+2 [flutter nested collection]
  • pull_to_refresh 1.6.2 [flutter]
  • sembast 2.4.8 [meta path synchronized]
  • sembast_web 1.2.0 [sembast idb_shim]
  • share 0.6.5+4 [meta mime flutter]
  • shared_preferences 0.5.12+4 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
  • simple_image_crop 0.1.3 [flutter]
  • storyboard 0.0.7 [flutter recase]
  • universal_html 1.2.3 [async charcode collection csslib html meta typed_data universal_io zone_local]
  • url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows]
  • video_player 0.10.12+5 [meta video_player_platform_interface video_player_web flutter]

dev dependencies:

  • flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:

  • _fe_analyzer_shared 12.0.0 [meta]
  • analyzer 0.40.6 [_fe_analyzer_shared args cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
  • archive 2.0.13 [crypto args path]
  • args 1.6.0
  • async 2.5.0-nullsafety.1 [collection]
  • boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner]
  • build 1.5.0 [analyzer async convert crypto logging meta path glob]
  • built_collection 4.3.2 [collection quiver]
  • built_value 7.1.0 [built_collection collection fixnum quiver]
  • characters 1.1.0-nullsafety.3
  • charcode 1.2.0-nullsafety.1
  • cli_util 0.2.0 [path]
  • clock 1.1.0-nullsafety.1
  • cloud_firestore_platform_interface 2.2.0 [flutter meta collection firebase_core plugin_platform_interface]
  • cloud_firestore_web 0.2.1 [flutter flutter_web_plugins http_parser meta firebase_core firebase_core_web cloud_firestore_platform_interface js]
  • code_builder 3.5.0 [built_collection built_value collection matcher meta]
  • collection 1.15.0-nullsafety.3
  • connectivity 0.4.9+5 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web]
  • connectivity_for_web 0.3.1+4 [connectivity_platform_interface flutter_web_plugins flutter]
  • connectivity_macos 0.1.0+7 [flutter]
  • connectivity_platform_interface 1.0.6 [flutter meta plugin_platform_interface]
  • convert 2.1.1 [charcode typed_data]
  • crypto 2.1.5 [collection convert typed_data]
  • csslib 0.16.2 [source_span]
  • dart_style 1.3.9 [analyzer args path source_span]
  • devicelocale 0.2.3 [flutter]
  • extended_image_library 0.2.3 [flutter path_provider http_client_helper crypto]
  • fake_async 1.2.0-nullsafety.1 [clock collection]
  • ffi 0.1.3
  • file 5.2.1 [intl meta path]
  • firebase_analytics_platform_interface 1.0.3 [flutter meta]
  • firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta]
  • firebase_auth_platform_interface 2.1.3 [flutter meta firebase_core plugin_platform_interface]
  • firebase_auth_web 0.3.2 [flutter flutter_web_plugins meta http_parser intl firebase_core firebase_core_web firebase_auth_platform_interface js]
  • firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver]
  • firebase_core_web 0.2.1 [firebase_core_platform_interface flutter flutter_web_plugins meta js]
  • fixnum 0.10.11
  • flutter_blurhash 0.5.0 [flutter meta]
  • flutter_cache_manager 2.0.0 [flutter path_provider uuid http path sqflite pedantic clock file rxdart]
  • flutter_local_notifications_platform_interface 1.0.1 [flutter plugin_platform_interface]
  • flutter_plugin_android_lifecycle 1.0.11 [flutter]
  • flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
  • glob 1.2.0 [async collection node_io path pedantic string_scanner]
  • google_sign_in_platform_interface 1.1.2 [flutter meta quiver]
  • google_sign_in_web 0.9.2 [google_sign_in_platform_interface flutter flutter_web_plugins meta js]
  • html 0.14.0+4 [csslib source_span]
  • http 0.12.2 [http_parser path pedantic]
  • http_client_helper 0.2.1 [http]
  • http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
  • idb_shim 1.12.2 [sembast collection path js]
  • image_picker_platform_interface 1.1.1 [flutter meta http plugin_platform_interface]
  • intl 0.16.1 [path]
  • js 0.6.3-nullsafety.1
  • logging 0.11.4
  • matcher 0.12.10-nullsafety.1 [stack_trace]
  • meta 1.3.0-nullsafety.4
  • mime 0.9.7
  • modal_bottom_sheet 1.0.1-dev [flutter]
  • nested 0.0.4 [flutter]
  • node_interop 1.2.0 [js]
  • node_io 1.1.1 [node_interop path]
  • octo_image 0.3.0 [flutter flutter_blurhash]
  • open_iconic_flutter 0.3.0 [flutter]
  • package_config 1.9.3 [path charcode]
  • package_info 0.4.3+2 [flutter]
  • path 1.8.0-nullsafety.1
  • path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
  • path_provider_macos 0.0.4+6 [flutter]
  • path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface]
  • path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32]
  • pedantic 1.9.2 [meta]
  • petitparser 3.1.0 [meta]
  • platform 2.2.1
  • plugin_platform_interface 1.0.3 [meta]
  • process 3.0.13 [file intl meta path platform]
  • pub_semver 1.4.4 [collection]
  • quiver 2.1.5 [matcher meta]
  • recase 2.0.1
  • rxdart 0.24.1
  • shared_preferences_linux 0.0.2+4 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
  • shared_preferences_macos 0.0.1+11 [shared_preferences_platform_interface flutter]
  • shared_preferences_platform_interface 1.0.4 [meta flutter]
  • shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
  • shared_preferences_windows 0.0.1+3 [shared_preferences_platform_interface flutter ffi file meta path path_provider_platform_interface path_provider_windows]
  • sky_engine 0.0.99
  • source_gen 0.9.8 [analyzer async build dart_style glob meta path pedantic source_span]
  • source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph]
  • sqflite 1.3.2+1 [flutter sqflite_common path]
  • sqflite_common 1.0.2+1 [synchronized path meta]
  • stack_trace 1.10.0-nullsafety.2 [path]
  • stream_channel 2.1.0-nullsafety.1 [async]
  • string_scanner 1.1.0-nullsafety.1 [charcode source_span]
  • synchronized 2.2.0+2
  • term_glyph 1.2.0-nullsafety.1
  • test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
  • typed_data 1.3.0-nullsafety.3 [collection]
  • universal_io 1.0.1 [meta zone_local]
  • url_launcher_linux 0.0.1+4 [flutter]
  • url_launcher_macos 0.0.1+9 [flutter]
  • url_launcher_platform_interface 1.0.9 [flutter meta plugin_platform_interface]
  • url_launcher_web 0.1.5+1 [url_launcher_platform_interface flutter flutter_web_plugins meta]
  • url_launcher_windows 0.0.1+3 [flutter]
  • uuid 2.2.2 [crypto convert]
  • vector_math 2.1.0-nullsafety.3
  • video_player_platform_interface 2.2.0 [flutter meta]
  • video_player_web 0.1.4+1 [flutter flutter_web_plugins meta video_player_platform_interface]
  • wakelock 0.1.4+2 [flutter]
  • watcher 0.9.7+15 [async path pedantic]
  • web_socket_channel 1.1.0 [async crypto stream_channel]
  • win32 1.7.3 [ffi]
  • xdg_directories 0.1.2 [meta path process]
  • xml 4.5.1 [collection convert meta petitparser]
  • xxtea 2.0.3
  • yaml 2.2.1 [charcode collection string_scanner source_span]
  • zone_local 0.1.2```


cloud_firestore bug

Most helpful comment

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'

All 10 comments

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

Flutter doctor

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

main.dart

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
              },
            );
          },
        ),
      ),
    );
  }
}

index.html

  <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>

pubspec.yaml

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
Was this page helpful?
0 / 5 - 0 ratings