Skip to content

fix: ignore the enclosing slot when reading another slot by id - #365

Merged
arbrandes merged 1 commit into
openedx:mainfrom
arbrandes:arbrandes/slot-operations-by-id
Nov 26, 2026
Merged

arbrandes merged 1 commit into
openedx:mainfrom
arbrandes:arbrandes/slot-operations-by-id

Conversation

@arbrandes

Copy link
Copy Markdown
Contributor

Description

This fixes #364. Hooks that read a slot by ID, like useWidgetsForId, useWidgetOperations and useWidgetOptionsForId, all go through useSlotOperations, which took children and idAliases from the slot context. That context belongs to whatever slot encloses the caller, not necessarily the slot being asked about. So reading slot B from inside slot A gave you slot A's children as B's defaultContent widget, plus anything registered under A's aliases.

Now the enclosing slot's children and aliases only apply when its ID matches the one being asked for. A slot read from outside has no default content and no aliases, which is how it should be: those only exist where the slot is rendered. It's an exact ID match, not one that also accepts the enclosing slot's aliases, since every caller that means "my own slot" already passes the slot's own ID.

None of the callers in shell/ and runtime/ relied on the old behaviour. NavDropdownMenuSlot reads its slot by ID from inside header.primaryLinks.v1, which has no children or aliases, so its output doesn't change. The new tests in runtime/slots/hooks.test.tsx cover reading both the enclosing slot and a different one.

LLM usage notice

Built with assistance from Claude.

Hooks that read a slot by id no longer pick up the default content and aliases of whatever slot encloses the caller.

Fixes openedx#364.

Co-Authored-By: Claude <noreply@anthropic.com>
@arbrandes
arbrandes merged commit 8e97681 into openedx:main Nov 26, 2026
5 checks passed
@openedx-semantic-release-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.0.0-alpha.20 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reading a slot by ID from inside another slot picks up that slot's children

2 participants