Skip to content

Dexie returns duplicated object after manually deleting the database and re-populate it.  #2011

@laukaichung

Description

@laukaichung

From: https://stackoverflow.com/questions/78618896/dexie-returns-duplicated-object-after-manually-deleting-the-database-and-re-popu

After deleting Dexie database manually, if you do not refresh the page, it will return duplicated data, even though the chrome inspector shows there are no duplicated rows in the IndexedDB. However, the issue goes away when you refresh the page right away after each database deletion.

Example: https://codesandbox.io/p/sandbox/dexie-issue-forked-djwxz6?file=%2Fsrc%2Findex.tsx

db config:

import Dexie, { EntityTable, Table } from "dexie";

const VERSION = 4.1;

export class MySubClassedDexie extends Dexie {
  playlists!: EntityTable<Playlist, "id">;

  constructor() {
    super("myDatabase");
    this.version(VERSION).stores({
      playlists: "++id,*competitionIds",
    });
  }
}

export const db = new MySubClassedDexie();

export const defaultPlaylists: Playlist[] = [
  {
    id: 1,
    competitionIds: [3, 4],
    title: "The Trial",
  },
  {
    id: 2,
    competitionIds: [1, 2],
    title: "Confederations Cup",
  },
];

db.on("populate", async () => {
  await db.playlists.bulkAdd(defaultPlaylists);
});

export interface Playlist {
  competitionIds: CompetitionId[];
  title: string;
  id: number;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions