Skip to content

fix: hide masquerade bar for anonymous users and on failed loads#266

Open
arbrandes wants to merge 1 commit into
openedx:mainfrom
arbrandes:arbrandes/fix-masquerade-behavior
Open

fix: hide masquerade bar for anonymous users and on failed loads#266
arbrandes wants to merge 1 commit into
openedx:mainfrom
arbrandes:arbrandes/fix-masquerade-behavior

Conversation

@arbrandes
Copy link
Copy Markdown
Contributor

Description

Fixes #265.

Anonymous users no longer mount MasqueradeBar: the slot op is gated on authenticated: true, so the component never runs for them and the masquerade query is never fired.

For authenticated users, the bar now hides on any failed load instead of rendering a partial shell with an "Unable to load masquerade options." alert. The LMS's 302-to-login redirect for denied masquerade requests is detected via the final response URL and surfaced as a 403-shaped error, so the existing denial branch hides the bar. Mutation errors after the bar has rendered still surface as before.

LLM usage notice

Built with assistance from Claude.

Anonymous users no longer mount MasqueradeBar: the slot op is gated
on authenticated: true so the component never runs for them and the
masquerade query is never fired.

For authenticated users, the bar now hides on any failed load
instead of rendering a partial shell with a "failed to load" alert.
The LMS's 302-to-login response for denied masquerade requests is
transparently followed by browser XHR, so it is detected via the
final response URL and surfaced as a 403-shaped error; the existing
denial branch then hides the bar. Mutation errors after the bar has
rendered still surface as before.

Co-Authored-By: Claude <noreply@anthropic.com>
@arbrandes arbrandes force-pushed the arbrandes/fix-masquerade-behavior branch from 967c6af to 7ed1f25 Compare May 14, 2026 11:04
Comment on lines +71 to 77
* Anything other than a successful load with `success: true` hides the bar:
* 403, 200 with `success: false`, network errors, 5xx, redirected requests.
*/
function isQueryDenied(query: { isError: boolean, error: unknown, data: MasqueradeStatus | undefined }): boolean {
if (query.isError) {
return getHttpStatus(query.error) === 403;
return true;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The PR description says

The LMS's 302-to-login redirect for denied masquerade requests is detected via the final response URL and surfaced as a 403-shaped error

That doesn't seem to match up with the change to deny on all errors here. Am I looking in the wrong spot?

Copy link
Copy Markdown
Contributor Author

@arbrandes arbrandes May 14, 2026

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah! Yeah, the changes in api.ts match the PR description.

I guess that changes my question to: "why is isQueryDenied changing?"

The previous logic matched the previous comment

Other failures (network, 5xx) are treated as "couldn't load" and surface as an alert.

Is that not desired behavior?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it's not desired. This is because, as I just realized when fixing this, one of the error modes - "couldn't load" - also happens when simply being logged out. This is because the backend returns a 302 instead of a 403 (why it would do that for an XHR request, I don't even dare guess), and, not knowing what to do with it, React Query just treats it as a network failure, renders the bar, and then the alert.

This made me think that any error except a mutation error should result in the bar not showing, because otherwise, a regular learner would suddenly be able to see the bar because of an actual network failure.

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.

Masquerade bar mounts for anonymous users and shows partial shell on failed loads

4 participants