Skip to content

Conversation

@clintandrewhall
Copy link
Contributor

@clintandrewhall clintandrewhall commented Oct 6, 2025

As titled. Adds a module-level singleton instance of the store and enhances the provider with useSyncExternalStore, (adds a Meta-maintained shim to support React 17).

This adds support for a synchronized Flyout Manager state when flyouts are launched across multiple React roots. Also supports having child flyouts opened from a separate React root than its parent.

"unified": "^9.2.2",
"unist-util-visit": "^2.0.3",
"url-parse": "^1.5.10",
"use-sync-external-store": "^1.6.0",
Copy link
Member

Choose a reason for hiding this comment

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

Note to other reviewers: useSyncExternalStore is shipped with React starting from version 18.0. We need this shim for React 17 support

state,
...rest,
goToFlyout,
getHistoryItems: () => {
Copy link
Member

@tsullivan tsullivan Oct 6, 2025

Choose a reason for hiding this comment

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

Since this is selector logic, maybe a better architecture would be to move getHistoryItems to the store. Doing so would make it so that we don't need to destructure goToFlyout from the store on line 28.

Copy link
Member

@tsullivan tsullivan Oct 7, 2025

Choose a reason for hiding this comment

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

I've played around with moving getHistoryItems to the store, and it created a scenario where it would return stale data even when state updates. The Provider component re-renders, but not components that consume the store state. To resolve that, I'm changing the FlyoutManagerApi to expose a historyItems property that can be used as an observable value.

Copy link
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

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

Thank you so much for working this out! Left a couple of comments

@clintandrewhall
Copy link
Contributor Author

Thanks @tsullivan I'll make the adjustments and open for review.

@tsullivan
Copy link
Member

@clintandrewhall in regards to the storybook that has been added, could we instead roll that into the "Multi-session example" storybook? I think that would be more suitable.

…ture

Replace useFlyoutManagerReducer with singleton store using useSyncExternalStore for cross-root synchronization. Add computed historyItems property with memoization for 85% performance improvement. Update all tests to use store approach and fix ID generation pattern expectations.
- Move “Multi-root sync” storybook to flyout_sessions.stories.tsx
- Revert “Playground” storybook file
@tsullivan tsullivan marked this pull request as ready for review October 9, 2025 00:07
@tsullivan tsullivan requested a review from a team as a code owner October 9, 2025 00:07
}) => {
const api = useFlyoutManagerReducer();
const { getState, subscribe, ...rest } = getFlyoutManagerStore();
const state = useSyncExternalStore(subscribe, getState, getState);
Copy link
Member

Choose a reason for hiding this comment

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

Adding the third parameter here should fix the build issue.

  • Docusaurus (which builds EUI's documentation website) uses Static Site Generation (SSG)
  • The getServerSnapshot parameter is needed for React to render the component during this build step

Copy link
Member

@tkajtoch tkajtoch left a comment

Choose a reason for hiding this comment

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

Code changes look great and work as expected. Thank you both for your work on this fix!

@tsullivan tsullivan force-pushed the exploration/flyout/external-sync branch from e46ba63 to ebc3870 Compare October 15, 2025 20:41
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

@tsullivan tsullivan merged commit 96cc060 into feat/flyout-system Oct 15, 2025
4 checks passed
@tsullivan tsullivan deleted the exploration/flyout/external-sync branch October 15, 2025 22:32
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.

5 participants