Make redux.initialize() wait until Redux is ready by griffpatch · Pull Request #9180 · ScratchAddons/ScratchAddons · GitHub
Skip to content

Make redux.initialize() wait until Redux is ready - #9180

Merged
apple502j merged 2 commits into
ScratchAddons:masterfrom
griffpatch:codex/fix-redux-initialize
Sep 26, 2026
Merged

apple502j merged 2 commits into
ScratchAddons:masterfrom
griffpatch:codex/fix-redux-initialize

Conversation

@griffpatch

@griffpatch griffpatch commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Some userscripts start before Scratch has finished setting up Redux. If they call addon.tab.redux.initialize() too early, it currently returns straight away and their listener is never connected.

This creates the Redux event channel earlier and lets addons wait until the first real Redux state is available:

await addon.tab.redux.initialize();

Addons that only listen for later changes can continue calling it without await.

waitForState() now waits for Redux to be ready before checking the state.

The readiness promise exists even while Redux is still loading. If it is missing, initialize() now throws an error instead of carrying on as though Redux were ready.

Fixes #7933

@pufferfish101007 pufferfish101007 added the scope: addon api Related to the addon.* JS APIs or other ways for addons to provide features label Sep 9, 2026
Comment thread addon-api/content-script/ReduxHandler.js Outdated
Comment thread addon-api/content-script/ReduxHandler.js Outdated
The promise should exist even while Redux is still loading. If it is
missing, throw an error instead of carrying on as though Redux is ready.

Also change "Existing callers" to "Callers", since the same advice
applies to future addons.
@apple502j
apple502j merged commit 6288f21 into ScratchAddons:master Sep 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: addon api Related to the addon.* JS APIs or other ways for addons to provide features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make redux.initialize() async

5 participants