matrix-org / matrix-js-sdk

Matrix Client-Server SDK for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IndexedDBStore: createUser is undefined, it should be set with setUserCreator when upgrading 29.1.0 -> 30.3.0

WebFreak001 opened this issue · comments

error:

Failed initializing matrix:  Error: createUser is undefined, it should be set with setUserCreator()!
    startup http://localhost:8080/node_modules/.vite/deps/chunk-AUCUNUAW.js?v=96c31d21:167359
    startup http://localhost:8080/node_modules/.vite/deps/chunk-AUCUNUAW.js?v=96c31d21:167357
    promise callback*startup http://localhost:8080/node_modules/.vite/deps/chunk-AUCUNUAW.js?v=96c31d21:167355
    startClient http://localhost:8080/src/client/initMatrix.js:42

API call:

    const indexedDBStore = new sdk.IndexedDBStore({
      indexedDB: global.indexedDB,
      localStorage: global.localStorage,
      dbName: 'web-sync-store',
    });
    await indexedDBStore.startup(); // <-- fails here

    this.matrixClient = sdk.createClient({
      baseUrl: secret.baseUrl,
      accessToken: secret.accessToken,
      userId: secret.userId,
      store: indexedDBStore,
      cryptoStore: new sdk.IndexedDBCryptoStore(global.indexedDB, 'crypto-store'),
      deviceId: secret.deviceId,
      timelineSupport: true,
      cryptoCallbacks,
      verificationMethods: [
        'm.sas.v1',
      ],
    });

the creation is almost exactly like what the API docs are suggesting to use, so I don't know what's going wrong here:

let opts = { indexedDB: window.indexedDB, localStorage: window.localStorage };
let store = new IndexedDBStore(opts);
await store.startup(); // load from indexed db

temporary workaround using undocumented as well as deprecated functions, but at least make it work for now:

call

indexedDBStore.setUserCreator(uid => new sdk.User(uid));

before .startup()

The setUserCreator API itself is undocumented, which probably means it wasn't meant to be exposed and was accidentally pushed as public API. I'd recommend not using it, even if it's mentioned in the error message.

introduced via #3796, cc @MidhunSureshR

in case users are supposed to call the APIs in a different order now, I have opened #3987 now that would update the documentation to reflect that.

That approach seems to work on my project and doesn't use any deprecated or undocumented APIs, but I don't know if it comes with any downsides since I'm not in too deep on the internal project structure.