apache / apache/pouchdb

`db.type() is deprecated` warning because `._remote` is not properly initialized when using multiple database.

Open
#8,983 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
17.6k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

This is a re-file of https://github.com/pouchdb/pouchdb/issues/7675 with a repro. This may also be the cause of other issue such as #6477 and #8971.

### Issue

Consider the following code:

```ts
import PouchDB from "pouchdb";
import PouchDBFind from "pouchdb-find";

PouchDB.plugin(PouchDBFind);

const db1 = new PouchDB("db-1");
console.log(db1._remote); // expected: `false`, observed: `false`
const db2 = new PouchDB("db-2");
console.log(db2._remote); // expected: `false`, observed: `undefined`

// Triggers a warning.
db2.createIndex({
index: { fields: ["some_field"] },
});
```

This causes the following output

```
false
undefined
[console warning] db.type() is deprecated and will be removed in a future version of PouchDB
```

The second line should be `false` rather than `undefined`, same as the first line.

This warning is logged from:

https://github.com/pouchdb/pouchdb/blob/2876834bd0860cf97bf2f451f06988753ad56da9/packages/node_modules/pouchdb-utils/src/isRemote.js#L13-L26

The code in question checks whether the DB's `_remote` field is a boolean. As the second database is not properly initialized with this field, it triggers the deprecation check.

### Info

- Environment: Browser
- Platform: Chrome
- Adapter: IndexedDB (default)
- Server: N/A

### Reproduce

To run the reproduction case from above, use the following commands:

```shell
git clone https://github.com/lgarron/pouchdb-deprecation-warning-repro && cd pouchdb-deprecation-warning-repro
npm install # note: this is slow!
node script/dev.js
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.