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

Đang mở
#8,983 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
database

Hướng nghiên cứu

Bắt đầu với packages/node_modules/pouchdb-utils/src/isRemote.js và theo dõi cách _remote được khởi tạo cho instance cơ sở dữ liệu đầu tiên và các instance tiếp theo. Chạy reproduction được liên kết hoặc các lệnh trong issue; hoàn tất khi db2._remote là false và việc gọi createIndex không còn phát ra cảnh báo deprecation.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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:

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:

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
Ngôn ngữ chính
JavaScript
Star
17.6k
Fork
1.5k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/pouchdb

Tất cả issue của apache/pouchdb

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.