quarrant / mobx-persist-store

Persist and rehydrate observable properties in mobx store.
268 stars 14 forks source link

Mobx-persist-store shows up the "Converting circular structure to JSON" when I save array into the sessionstorage #108

Closed MelodyFish closed 1 year ago

MelodyFish commented 1 year ago

Console show the details:

 --> starting at object with constructor 'FiberNode'
 |     property 'stateNode' -> object with constructor 'HTMLElement'
--- property '__reactFiber$2k3uax4tvxn' closes the circle
at JSON.stringify (<anonymous>)
at StorageAdapter.<anonymous> (StorageAdapter.js:57:1)
MelodyFish commented 1 year ago

Here is my mobx store code:

import { makeAutoObservable, action } from 'mobx' import { makePersistable } from 'mobx-persist-store' import PlatformContent from '../pages/WorkPlatform/Content'

class TabStore {

tabsList = JSON.parse(JSON.stringify([{ name: 'work', key: '/', url: '', icon: <img src={require('@/assets/img/work_on.png')} width={13} />, closable: false, }]))

constructor() {
  makeAutoObservable(this)
  makePersistable(
    this, 
    { name: 'tabsList', properties: ['tabsList'], storage: window.sessionStorage },
  )
}
setTabsList(value) {
  this.tabsList = value
}

} export { TabStore }

MelodyFish commented 1 year ago

@codeBelt @jwoyame If you have time please check it, maybe it is a strange bug, thanks~