Skip to content

Index not defined error, but on this case it should work #7843

@marcusx2

Description

@marcusx2

Operating System

macOS

Browser Version

Safari 16.5.2

Firebase SDK Version

10.7.0

Firebase SDK Product:

Database

Describe your project's tooling

index.html with source tag. Just javascript.

Describe the problem

I get the Index not defined error under a specific circumstance, but on another circumstance I don't. It's weird.

This is the data I use

const data = {
    "posts": {
        "ts-functions": {
            "metrics": {
                "views": 1200000,
                "likes": 251000,
                "shares": 100,
             },
             "title": "Why you should use TypeScript for writing Cloud Functions",
             "author": "Doug",
         },
         "android-arch-3": {
              "metrics": {
                  "views": 900000,
                  "likes": 117000,
                  "shares": 144,
               },
               "title": "Using Android Architecture Components with Firebase Realtime Database (Part 3)",
               "author": "Doug",
          }
    }
}

Steps and code to reproduce issue

Given the data above, the following code snippet does not trigger the error

set(ref(db), data);
let mostViewedPosts = query(ref(db, 'posts'), orderByChild('metrics/views'));
let snapshot = await get(mostViewedPosts);

However, the next one does trigger the error

await set(ref(db), data);
let mostViewedPosts = query(ref(db, 'posts'), orderByChild('metrics/views'));
let snapshot = await get(mostViewedPosts);

The only difference is that on the second code snippet, I await the set method. It doesn't make any sense that the error would happen only if I await the set. If anything, if the error had to happen at all it should happen if I don't await. This looks like a bug to me.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions