IndexedDB 无效状态错误:无法在“IDBDatabase”上执行“事务”:正在关闭与ios safari的数据库连接

mtb9vblg  于 2022-12-16  发布在  IndexedDB
关注(0)|答案(1)|浏览(376)

我自2020年8月以来一直有问题,我仍然不知道如何重现,我使用dfahlander/Dexie.js来使用浏览器indexedDB。
这是我如何使用dexie的示例:-

import db from "./db";
import { useState, useEffect } from "react";
import axios from "axios";
import {   useParams } from "react-router-dom";

export default function App() {
  const params =   useParams();
  const [storedRead, setStoredRead] = useState();
  const [data,setData] = useState();

  useEffect(() => {
          db.reads
            .get({ hash: params.id })
            .then((data) => {
              setStoredRead(data);
              readRequest(data ? data.token : "");
            })
            .catch((e) => {
              //Here i am getting error with ios users, not all of them
              // InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.   
            });
 
  }, []);

  const readRequest = (token) => {
    axios
      .post(`${process.env.REACT_APP_API_URL}khatma/read`, {
        khatma: params.id,
        part: params.part,
        section: params.section,
        token: token, 
      })
      .then((res) => {
        if (res.data.token) {
          db.reads
            .put(
              {
                hash: params.id,
                token: res.data.token,
                ss: "",
                sa: "",
              },
              params.id
            )
            .then((event) => {
              db.reads.get({ hash: params.id }).then((read) => {
                setStoredRead(read);
                setData(res.data);
              });
              
            })
            .catch((e) => {
             
            });
  
        } else {
          setData(res.data);
  
          db.reads.get({ hash: params.id }).then((read) => {
            setStoredRead(read);
            setData(res.data);
          
          });
          
        }
    
      })
      .catch((error) => {
      
      });
  };

  return (
    <div className="App">
     
    </div>
  );
}

db.js文件:-

import Dexie from "dexie";
const db = new Dexie("khatmaDB");
db.version(2).stores({
  reads: "hash,token,sa,ss",
  khatmas: "hash,token"
});

console.log("dexie version", db.verno);

export default db;

自2020年8月以来,我有大约25 K的日志记录与以下错误:-
无效状态错误:无法在“IDBDatabase”上执行“事务”:数据库连接正在关闭。
这种情况只会发生在不同ios版本(11到14)的用户代理= ios safari中。CPU iPhone操作系统14_0像Mac OS X)苹果网络工具包/605.1.15(KHTML,像壁虎)版本/14.0移动的/15 E148 Safari/604.1
如果我们要求用户清除他的浏览器网站数据(iPhone设置〉Safari〉高级〉网站数据〉删除网站数据)。问题得到解决,即使他们有可用的iPhone存储空间超过20 GB,但我们不能要求每个用户删除他们的网站数据。
你知道这个问题的原因是什么吗?

yks3o0rb

yks3o0rb1#

嗯....我做了一些RND对这个问题,你只需创建全局错误处理服务,你可以把检查这个问题,只是重新加载应用程序,它会工作
如果(err.message.search('transaction' on 'IDBDatabase')〉-1){窗口位置重载()'}

相关问题