Skip to content

[V4] Using a custom path in createMMKV fails to save data #911

@ChristopherGabba

Description

@ChristopherGabba

Good morning Marc!

I was experimenting with parameters and noticed something ... interesting?

Previously I had:

export const mmkvStorage = createMMKV()

// Tanstack persist logic
export const clientPersister = {
  persistClient: (persistedClient: PersistedClient) => {
    const data = JSON.stringify(persistedClient)
    mmkvStorage.set(storageKey.reactQueryCache, data)
  },
  restoreClient: () => {
    const data = mmkvStorage.getString(storageKey.reactQueryCache)
    if (!data) {
      return undefined
    }
    return JSON.parse(data) as PersistedClient
  },
  removeClient: () => {
    mmkvStorage.remove(storageKey.reactQueryCache)
  },
} as Persister


// How I was using it in main App.tsx
  return (
    <PersistQueryClientProvider
      persistOptions={{ persister: clientPersister, maxAge: QUERY_STALE_TIMES.SEVEN_DAYS }}
      client={queryClient}
    >
      <App />
    </PersistQueryClientProvider>
  )

And it works fantastic -- super fast, rehydrates every time, queries maintain their stale / gc times and cached data, etc -- TLDR absolutely no issues.

I was reading the docs and just thought, interesting you can put storage ids and stuff in place, so I just changed this:

export const mmkvStorage = createMMKV({
  id: `app-data-storage`,
  path: `app/data`,
})

This was literally the only change I made and it was almost straight from the docs:

Image

Every time I opened the app, completely gone -- no hydrated data, all persistence failed. I would go as far to say that nothing was even writing correctly to begin with. I would have thought that just because there is an id and a path, it would sort of just organize it under a key-value folder in a different way.

Obviously nothing urgent, I just went back to my previous, but something seems broken here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions