Skip to content

feat: Tree multiple level loading support #8299

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

LFDanLu
Copy link
Member

@LFDanLu LFDanLu commented May 23, 2025

Closes

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link

rspbot commented May 23, 2025

Comment on lines +822 to +824
{/* TODO: wonder if there is something we can do to ensure that these depenedcies are provided, need to dig to make sure if there is an alternative */}
{/* NOTE: important to provide dependencies here, otherwise the nested level doesn't perform loading updates properly */}
<Collection items={rootData.items} dependencies={[isProjectsLoading, isDocumentsLoading, isProjectsLevel3Loading]}>
Copy link
Member Author

Choose a reason for hiding this comment

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

This feels a bit gross but is required to make sure the loading spinner in a nested row is properly updated when its loading state updates

@rspbot
Copy link

rspbot commented May 23, 2025

@rspbot
Copy link

rspbot commented May 23, 2025

@rspbot
Copy link

rspbot commented May 27, 2025

Build successful! 🎉

@rspbot
Copy link

rspbot commented May 27, 2025

Build successful! 🎉

@rspbot
Copy link

rspbot commented May 27, 2025

## API Changes

react-aria-components

/react-aria-components:UNSTABLE_TreeLoadingIndicator

-UNSTABLE_TreeLoadingIndicator <T extends {}> {
-  children?: ReactNode | ((UNSTABLE_TreeLoadingIndicatorRenderProps & {
-    defaultChildren: ReactNode | undefined
-})) => ReactNode
-  className?: string | ((UNSTABLE_TreeLoadingIndicatorRenderProps & {
-    defaultClassName: string | undefined
-})) => string
-  style?: CSSProperties | ((UNSTABLE_TreeLoadingIndicatorRenderProps & {
-    defaultStyle: CSSProperties
-})) => CSSProperties | undefined
-}

/react-aria-components:UNSTABLE_TreeLoadingSentinel

+UNSTABLE_TreeLoadingSentinel <T extends {}> {
+  children?: ReactNode | ((UNSTABLE_TreeLoadingSentinelRenderProps & {
+    defaultChildren: ReactNode | undefined
+})) => ReactNode
+  className?: string | ((UNSTABLE_TreeLoadingSentinelRenderProps & {
+    defaultClassName: string | undefined
+})) => string
+  isLoading?: boolean
+  onLoadMore?: () => any
+  scrollOffset?: number = 1
+  style?: CSSProperties | ((UNSTABLE_TreeLoadingSentinelRenderProps & {
+    defaultStyle: CSSProperties
+})) => CSSProperties | undefined
+}

@LFDanLu LFDanLu marked this pull request as ready for review May 30, 2025 22:23
@LFDanLu LFDanLu changed the title (WIP) Tree multiple loader support feat: Tree multiple level loading support May 30, 2025
Comment on lines +69 to +74
let focusedItem = tree.getItem(selectionState.focusedKey);
// TODO: do we want to have the same logic as useListState/useGridState where it tries to find the nearest row?
// We could possibly special case this loader case and have it try to find the item just before it/the parent
if (!focusedItem || focusedItem.type === 'loader' && !focusedItem.props.isLoading) {
selectionState.setFocusedKey(null);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

For now I've preserved the previous behavior of just focusing the tree if the loader disappears, but ideally we'd do something like useListState and useGridState where it looks for the closest focusable row as a substitute. Will handle that update upon refactoring some of that logic as noted in https://github.com/adobe/react-spectrum/pull/8326/files#r2116825740

Comment on lines +725 to +729
let memoedLoadMoreProps = useMemo(() => ({
onLoadMore,
// TODO: this collection will update anytime a row is expanded/collapsed becaused the flattenedRows will change.
// This means onLoadMore will trigger but that might be ok cause the user should have logic to handle multiple loadMore calls
collection: state?.collection,
Copy link
Member Author

Choose a reason for hiding this comment

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

think this should be ok, but open to discuss

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.

2 participants