Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#8219: don't let frames control sidebar panel via setPanels #8225

Merged
merged 3 commits into from
Apr 11, 2024

Conversation

twschiller
Copy link
Contributor

@twschiller twschiller commented Apr 11, 2024

What does this PR do?

Discussion

Demo

Future Work

  • For follow-up PR: review use of "showTemporarySidebarPanel", "updateTemporarySidebarPanel", "showSidebarForm". Should they ever be called from a frame? Or do the bricks need to run using target: top? We need to be careful not to break MV2 behavior expecations

Checklist

  • Add jest or playwright tests and/or storybook stories
  • Designate a primary reviewer: @fungairino

@twschiller twschiller changed the title #8219: don't let frames control sidebar #8219: don't let frames control sidebar by passing empty array of panels Apr 11, 2024
@twschiller twschiller added bug Something isn't working mv3 labels Apr 11, 2024
@twschiller twschiller changed the title #8219: don't let frames control sidebar by passing empty array of panels #8219: don't let frames control sidebar Apr 11, 2024
@twschiller twschiller changed the title #8219: don't let frames control sidebar #8219: don't let frames control sidebar panels Apr 11, 2024
Copy link
Contributor

@fregante fregante left a comment

Choose a reason for hiding this comment

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

Yeah this change makes sense, the iframes should not interact with the sidebar at all. I think all of this logic should be moved as high up as possible, e.g. discard any sidebar extensions when in iframes; discard all sidebar-related messages or ensure that they're never sent to frames.

@twschiller twschiller changed the title #8219: don't let frames control sidebar panels #8219: don't let frames control sidebar panel via setPanels Apr 11, 2024
@twschiller twschiller added this to the 1.8.13 milestone Apr 11, 2024
@twschiller
Copy link
Contributor Author

twschiller commented Apr 11, 2024

discard any sidebar extensions when in iframes

The sidebar starter brick refuses to activate any mod components when running in a frame:

return !isLoadedInIframe() && checkAvailable(this.definition.isAvailable);

But there are other calls that made their way to the controller: e.g.,

clearModComponentInterfaceAndEvents(extensionIds: UUID[]): void {

As mentioned in Future Work, we need to review all the calls in the sidebarController to either ignore or throw an error. But we'll need to ensure we're not breaking backward compatibility for calls in MV2 (e.g., showing sidebar forms from frames)

@fungairino
Copy link
Collaborator

One thing I noticed is that the panels variable isn't synchronized in the SidebarController

const panels: PanelEntry[] = [];

There's a comment on how the sidebarSlice handles race conditions here:

// The sidebarSlice handles the race condition with the panels loading by keeping track of the latest pending
// activatePanel request.

I'm a bit worried that we could run into this sort of buggy behavior again in the future so I'll spend some time in my spec slicing to investigate if there's any work here we could do to better prevent this sort of issue again.

@twschiller
Copy link
Contributor Author

twschiller commented Apr 11, 2024

One thing I noticed is that the panels variable isn't synchronized in the SidebarController

What do you mean by not synchronized? Javascript is single-threaded

I'm a bit worried that we could run into this sort of buggy behavior again in the future so I'll spend some time in my spec slicing to investigate if there's any work here we could do to better prevent this sort of issue again.

@fungairino that comment is specifically referring to the case of using the Show Sidebar brick to try to show a specific panel in the sidebar. So there's a race as to if the "Show Sidebar" brick is called before that panel has been added to the sidebar

The comment is saying that the sidebarSlice handles the race condition, so the sidebarController doesn't have to handle the race condition

@fregante
Copy link
Contributor

Will this also fix #8141? If the frames don't receive/handle the message, then we don't have to move the logic.

@fungairino
Copy link
Collaborator

fungairino commented Apr 11, 2024

What do you mean by not synchronized? Javascript is single-threaded

I'm thinking about improving the behavior if we have async calls that are removing all the panels and then updating them near the same time. Some way to more deterministically figure out the final state of panels given a series of aync calls to modify the panels, but maybe this is not exactly the right thing to worry about here.

@twschiller
Copy link
Contributor Author

twschiller commented Apr 11, 2024

Some way to more deterministically figure out the final state of panels given a series of aync calls to modify the panels, but maybe this is not exactly the right thing to worry about here.

The sidebar currently handles that and the React app initialization race by enforcing message order. That logic has by and large been working well:

function runListeners<Method extends keyof SidebarListener>(

@twschiller
Copy link
Contributor Author

Will this also fix #8141? If the frames don't receive/handle the message, then we don't have to move the logic.

Not in its current state. We need to clarify the behavior of open sidebar, show sidepanel form, etc. from iframes. I would recommend we merge this PR in though and treat those in separate PRs

@fungairino
Copy link
Collaborator

The sidebar currently handles that and the React app initialization race by enforcing message order. That logic has by and large been working well: pixiebrix-extension/src/sidebar/protocol.tsx

TIL! Thanks for the context!

@fungairino
Copy link
Collaborator

I tested in MV2 as well and it looks like it works well!

Copy link

When the PR is merged, the first loom link found on this PR will be posted to #sprint-demo on Slack. Do not edit this comment manually.

@fungairino fungairino merged commit b59631d into main Apr 11, 2024
21 of 22 checks passed
@fungairino fungairino deleted the feature/8219-blank-sidebar branch April 11, 2024 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mv3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants