Skip to content

feat: add backpack with localStorage persistence#214

Merged
takaokouji merged 6 commits into
developfrom
feature/backpack-localstorage
Mar 3, 2026
Merged

feat: add backpack with localStorage persistence#214
takaokouji merged 6 commits into
developfrom
feature/backpack-localstorage

Conversation

@takaokouji
Copy link
Copy Markdown

@takaokouji takaokouji commented Mar 3, 2026

Summary

Closes #213

Scratch 公式の backpack API はフォークには公開されていないため、xcratch の実装を参考に localStorage をバックエンドとして使用するバックパック機能を実装する。

Implementation Steps

  • Phase 1: backpack-api.js — localStorage バックエンド追加
  • Phase 2: containers/backpack.jsx — localStorage 対応
  • Phase 3: legacy-storage.ts — localStorage アセット URL 対応
  • Phase 4: render-gui.jsx — バックパック有効化
  • Phase Final: Integration Tests 更新

Changes

  • packages/scratch-gui/src/lib/backpack-api.js: localStorage バックエンド追加(host === 'localStorage' 分岐)
  • packages/scratch-gui/src/containers/backpack.jsx: token/username デフォルト値、localStorage アセットサーバースキップ
  • packages/scratch-gui/src/lib/legacy-storage.ts: localStorage アセット URL 生成(data: URL)対応
  • packages/scratch-gui/src/playground/render-gui.jsx: バックパック有効化、デフォルト localStorage
  • packages/scratch-gui/test/unit/lib/backpack-api.test.js: unit tests 追加 (9 tests)
  • packages/scratch-gui/test/unit/containers/backpack.test.jsx: unit tests 追加 (2 tests)
  • packages/scratch-gui/test/unit/lib/legacy-storage.test.js: unit tests 追加 (5 tests)
  • packages/scratch-gui/test/integration/backpack.test.js: integration tests 更新 (4 tests, describe.skip 削除)

Test Coverage

  • Unit tests: localStorage の CRUD 操作、コンテナ動作、legacy-storage URL 生成 (16 tests)
  • Integration tests: 4テスト (ブラウザでの動作確認用)

Add localStorage storage backend to backpack-api.js, ported from xcratch.
When host is set to 'localStorage', getBackpackContents/saveBackpackObject/
deleteBackpackObject operate on localStorage instead of a remote API server.
Also add getLocalStorageBackpackAssetURL for asset URL resolution.

Refs: #213
- Default token/username to 'localToken'/'localUser' when no session or
  URL params, enabling getContents() to work with localStorage host
- Skip asset server presave in handleDrop when host is 'localStorage'

Refs: #213
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 3, 2026

When backpackHost is 'localStorage', getBackpackAssetURL returns a
data: URL by looking up the asset in localStorage, instead of returning
an invalid 'localStorage/assetId.format' path URL.

Refs: #213
- Set backpackVisible to true (backpack always shown)
- Default backpackHost to 'localStorage' when no URL param
- URL param ?backpack_host= still allows custom remote API

Refs: #213
- Remove describe.skip (tests are now active)
- Replace 'Coming Soon' test with localStorage-based visibility test
- Add test for empty state when backpack first expanded
- Add test for localStorage persistence across page reload

Refs: #213
CSS Modules transforms class names, so use kebab-case 'backpack-list-inner'
(the original CSS class name) instead of camelCase 'backpackItem' on li elements.
Also add waitForLoadingFinished after page reload for stability.

Refs: #213
@takaokouji takaokouji merged commit 0e41812 into develop Mar 3, 2026
5 checks passed
@takaokouji takaokouji deleted the feature/backpack-localstorage branch March 3, 2026 17:47
takaokouji pushed a commit that referenced this pull request Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add backpack with localStorage persistence (ported from xcratch)

1 participant