localStorage が溢れる ── 世界線の cas を IndexedDB と二重に持っている

Open
#207 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 12 days

@ninjamasa is already working on this.

Since Oct 7, 2026.

Assessment

This issue has not been assessed yet.

Description

OS refactor

何が起きているか

localStorage の persist:root(redux-persist が Redux の状態を書く所)が、ブラウザの上限(約 5MB)に達して書けなくなる。

Error storing data QuotaExceededError: Failed to execute 'setItem' on 'Storage':
Setting the value of 'persist:root' exceeded the quota.

溢れると、それ以降の変更(どのスライスも)が保存されない。リロードすると、溢れる前の状態に戻る。

中身

ふだん使っているブラウザで測った値:

大きさ
persist:root 全体 約 5.2MB
└ worldLineGraph 約 4.4MB
└ ほかのスライス全部 数 KB

ほとんどが世界線の cas(各節の中身の控え)。

なぜ溢れるか

世界線の中身は 2 か所に置かれている。

 世界線を伸ばす
     │
     ├─→ Redux の cas(最大 300 件。古いものから捨てる = 手元の控え)──→ localStorage(redux-persist)
     │
     └─→ IndexedDB(world-line-graph-db。全部ずっと残る = 本当の置き場)
           ↑ 控えから捨てた節が要る時は、ここから取ってくる(useCasScope)
  • 本当の置き場は IndexedDB(worldLineGraphListener.ts が全部書いている)
  • Redux の cas は控えで、MAX_CAS_ENTRIES = 300 を超えたら古いものから捨てる(worldLineGraphSlice.ts)
  • その控えを、redux-persist が localStorage にも丸ごと書いている ── 二重持ち

上限は件数で決めていて、1 件の大きさを見ていない。海の姿(sea-arrangement)は 1 節で 100〜200KB ある(泡が 200 個、一覧の札まで全部入る)ので、海の節が 30〜50 個たまるだけで 5MB に届く。

直し方の案

  • A. cas を localStorage に書かない(おすすめ)
    IndexedDB に全部あるので、書かなくても失うものはない。グラフ(節の DAG)は小さいので、これまでどおり persist してよい。
    リロード直後は控えが空なので IndexedDB から取ってくる ── useCasScope の pending がもうこの場面(「参照はあるのに値が手元に無い」)を扱っている。
    redux-persist の transform か、worldLineGraph を入れ子の persist にして cas だけ blacklist する形になりそう。
  • B. 上限を件数ではなく大きさで決める
    二重持ちは残るので、根本の手当てにはならない。

確かめること

  • cas を書かなくしたあと、リロードして海・囲碁・メモの世界線がそのまま戻る
  • 「はじめて開いた人」の見本の海(useSeedOnFirstOpen / worldLineSeed)が、記録の無い時だけ撒かれる(グラフの読み戻しで「はじめて」を判断しているので、グラフは persist し続ける必要がある)
  • すでに溢れているブラウザで開いても、壊れずに直る
Dominant language
TypeScript
Stars
1
Forks
0
Avg merge
9d 13h
Merged PRs (30d)
10

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fumicode/bublys-org

All issues in fumicode/bublys-org

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.