Skip to content

Conversation

@georgyangelov
Copy link
Contributor

This PR exposes a new set of functions through the GUIConfig interface (used by the standalone package) that allow for configuring a different backpack backend.

The interfaces are in packages/scratch-gui/src/gui-config.ts.

To keep backwards-compatibility, the new interface is implemented by default in packages/scratch-gui/src/lib/legacy-backpack-storage.ts and used in packages/scratch-gui/src/lib/legacy-storage.ts.

The LegacyBackpackStorage class gets a constructor config readAuth(session: BackpackSession | undefined): Promise<LegacyBackpackAuth> that allows controlling the session externally and through an async function (that has a chance to e.g. refresh a JWT before sending the request). The session parameter is a way to both allow externally-controlled session or the previous behavior where the session is taken from a Redux store that is shared between scratch-gui and scratch-www.

…et of interfaces

This allows other projects to specify their own backpack server implementation and API.
If the previous code ended up in this state - it was already invalid
since the backpack was shown but it would say "No items" instead of
indicating to the user that they are logged out
@georgyangelov georgyangelov requested a review from a team as a code owner February 10, 2026 10:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Expose a configurable backpack storage interface via GUIConfig, while preserving legacy backpack behavior through a new LegacyBackpackStorage adapter.

Changes:

  • Added GUIBackpackStorage interfaces/types (session, item, serialization) to enable pluggable backpack backends.
  • Implemented legacy backpack backend as LegacyBackpackStorage and wired it into LegacyStorage.
  • Updated the Backpack container/UI to use storage.backpackStorage instead of legacy backpack-api functions, and gated rendering on configuration.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/scratch-gui/src/lib/legacy-storage.ts Wires the new legacy backpack storage into LegacyStorage and registers backpack asset web store via the new helper.
packages/scratch-gui/src/lib/legacy-backpack-storage.ts New legacy backpack backend implementing GUIBackpackStorage with host/session/auth handling and xhr calls.
packages/scratch-gui/src/lib/backpack/payload-serializable-data.ts Adds an adapter to bridge existing payload builders to the new SerializableData interface.
packages/scratch-gui/src/lib/backpack-api.js Removes old backpack CRUD/payload exports; keeps only fetch helpers for code/sprite retrieval.
packages/scratch-gui/src/index-standalone.tsx Exposes LegacyBackpackStorage from the standalone entrypoint.
packages/scratch-gui/src/gui-config.ts Introduces GUIBackpackStorage + related types and PropTypes; adds optional backpackStorage to GUIStorage.
packages/scratch-gui/src/containers/backpack.jsx Migrates backpack CRUD to storage.backpackStorage and updates session propagation.
packages/scratch-gui/src/components/gui/gui.jsx Prevents rendering Backpack UI unless a backpack storage is configured.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

Test report for scratch-gui

  6 files  +4    4 errors  62 suites  ±0   9m 36s ⏱️ + 1m 5s
398 tests ±0  389 ✅  - 1  8 💤 ±0  1 ❌ +1 
416 runs  ±0  407 ✅  - 1  8 💤 ±0  1 ❌ +1 

For more details on these parsing errors and failures, see this check.

Results for commit 42458e1. ± Comparison against base commit 40d5142.

♻️ This comment has been updated with latest results.

@georgyangelov
Copy link
Contributor Author

@cwillisf Can you please review?

There is a test failing but I would argue that it's incorrect/incomplete behaviour that it was testing, so I would vote for removing it if you agree. Here's what happens.

This is the test:

test('Backpack can be expanded with backpack host param', async () => {
        await loadUri(`${uri}?backpack_host=https://backpack.scratch.mit.edu`);

        // Try activating the backpack from the costumes tab to make sure it isn't pushed off
        await clickText('Costumes');

        // Check that the backpack header is visible and wrapped in a coming soon tooltip
        await clickText('Backpack'); // Not wrapped in tooltip
        await clickText('Backpack is empty'); // Make sure it can expand, is empty
        const logs = await getLogs();
        await expect(logs).toEqual([]);
    });

It tests opening the backpack with just the host set (without a logged-in user) and validates that it shows "Backpack is empty". I would argue that having the backpack show "Backpack is empty" when in fact it may not be (it's just that there is no user logged in) is incorrect behavior. In the changes I made - it would show an error instead. My thinking is - this shouldn't happen in scratch-www since when there is no session - the backpack is hidden, so the user can't click it.

What do you think?

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.

1 participant