Skip to content
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

null evaluated as undefined in release mode on web (Chrome browser) #50070

Open
russellwheatley opened this issue Sep 28, 2022 · 0 comments
Open
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-dart2js

Comments

@russellwheatley
Copy link

russellwheatley commented Sep 28, 2022

This tracker is for issues related to:

  • dart2js

Environment

  • Dart SDK Version (dart --version) - Dart SDK version: 2.18.1 (stable)
  • Whether you are using Windows, MacOSX, or Linux (if applicable) - Using MacOSX
  • Whether you are using Chrome, Safari, Firefox, Edge (if applicable) - Using Chrome

There is a bug with how a null value is being evaluated, it is coming through as undefined on the web when ran in release mode.

For context, here is the pull request on FlutterFire that has a simple code illustration of the bug in the description.

In a nutshell:

//`media.first` will have the value of `null` in Dart. When ran in release mode, it is being evaluated in JavaScript as `undefined` 
final List<String?> media = List<String?>.filled(1, null);

If you wish to see a demonstration. Follow these steps:

  1. Clone FlutterFire repo
  2. Run melos bootstrap within project so all packages are linked together.
  3. From root of project, navigate to packages/cloud_firestore/cloud_firestore/example in your terminal.
  4. Run flutter pub get
  5. Paste the following code into packages/cloud_firestore/cloud_firestore/example/lib/main.dart:
import 'package:cloud_firestore_example/firebase_config.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:cloud_firestore/cloud_firestore.dart';



Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseConfig.platformOptions);

  runApp(FirestoreExampleApp());
}

class FirestoreExampleApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Bug Report',
      theme: ThemeData.dark(),
      home: Scaffold(
        body: Center(child: Column(children: [
          ElevatedButton(
            onPressed: () async {
              DocumentReference users = FirebaseFirestore.instance.collection('flutter-tests').doc('1');

              final List<String?> media = List<String?>.filled(1, null);

              // This will error even though `media.first` is a `null` object
              await users.set({'greatField2': media.first});
            },
            child: const Text('Press to see exception using `media.first`'),
          ),
          ElevatedButton(
            onPressed: () async {
              DocumentReference users = FirebaseFirestore.instance.collection('flutter-tests').doc('1');

              // This will not error when using explicit `null` value
              await users.set({'greatField2': null});

              //
            },
            child: const Text('Press to see no exception with explicit `null` value'),
          ),
        ],),),
      ),
    );
  }
}
  1. From packages/cloud_firestore/cloud_firestore/example directory, run flutter run --no-pub -d chrome --release.
  2. Open terminal in chrome to see the exception. The top button will throw exception, the bottom will not.
  3. if you want to see the final value (null) before it goes to the interop layer for JavaScript, you can add some logging here. data will be the value that is passed into set() API.

I think I'm in the right place 😅, but let me know if it should be elsewhere or if you need any further information. Thanks.

@lrhn lrhn added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants