Skip to content

Conversation

erwanMarmelab
Copy link
Contributor

@erwanMarmelab erwanMarmelab commented Aug 5, 2025

Problem

ListIterator has a drawback: empty, loading and error states appear inside the wrapper (often a <ul>). It makes it unusable in most cases.

TODO

  • Update new headless docs.

Solution

  • remove the component
  • update <SingleFieldList> and <SimpleList> to not use it
  • Update WithListContext to accept optional empty, loading and error components
  • Add a ListIterator alias for WithListcontext

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • [ ] The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date

Copy link
Contributor

@Madeorsk Madeorsk left a comment

Choose a reason for hiding this comment

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

Does SimpleList still works when you pass data manually? It doesn't seem to be used and tested anymore.

Also, this is missing:

  • Update WithListContext to accept optional empty, loading and error components

Copy link
Contributor

@Madeorsk Madeorsk left a comment

Choose a reason for hiding this comment

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

A few issues related to WithListContext.

Copy link
Contributor

@Madeorsk Madeorsk left a comment

Choose a reason for hiding this comment

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

Nearly done!

</ReferenceArrayFieldBase>
</ListIterator>
</ListBase>
<ListBase
Copy link
Member

Choose a reason for hiding this comment

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

This code isn't better than the previous one. It underlines the fact that RecordsIterator should probably return null while loading, without any warning.

Copy link
Contributor

@Madeorsk Madeorsk Sep 5, 2025

Choose a reason for hiding this comment

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

As ListBase doesn't provide something to hide the content while data is loading (there is a loading prop, but it only handles pending authentication), here is the current API to perfectly reproduce the previous behavior of ListIterator.

export const PostList = () => (
    <ListBase>
        <WithListContext loading={null} errorElement={null} offline={null} empty={null}>
            <RecordsIterator>
                <ReferenceArrayFieldBase reference="tags" source="tag_ids">
                    <TagList />
                </ReferenceArrayFieldBase>
            </RecordsIterator>
        </WithListContext>
    </ListBase>
);

wdyt?


export interface WithListContextProps<RecordType extends RaRecord> {
if (isPending === true && loading) {
Copy link
Member

Choose a reason for hiding this comment

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

loading=null is a valid ReactNode and should be taken into account. I thing you should change the test to be as in https://github.com/marmelab/react-admin/pull/10864/files#diff-cdac9daf5ac7f12fe651a4357b777c27564f7372b0387256dd630f0a9d07c479

hasTertiaryText={!!tertiaryText}
/>
}
empty={empty ?? <></>}
Copy link
Member

Choose a reason for hiding this comment

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

should be empty ?? null IMO

render={({ data }) => (
<Root className={className} {...sanitizeListRestProps(rest)}>
<RecordsIterator
data={data}
Copy link
Member

Choose a reason for hiding this comment

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

I don't know why you need data here

Copy link
Contributor

Choose a reason for hiding this comment

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

This component may be called out of a list context (with data passed manually in props), so RecordsIterator may need to get data explicitly as it won't be able to get them from the list context. I add a comment to state it explicitly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't you pass it to WithListContext instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is passed to WithListContext through ...props, which then pass it down to the render function. But we need to keep it here as there's still no ListContext under WithListContext.

{...sanitizeListRestProps(rest)}
>
<RecordsIterator
data={data}
Copy link
Member

Choose a reason for hiding this comment

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

same

@fzaninotto fzaninotto changed the title Remove ListIterator [DNM] Remove ListIterator Aug 13, 2025
@Madeorsk Madeorsk added RFR Ready For Review and removed WIP Work In Progress labels Sep 9, 2025
@Madeorsk Madeorsk changed the title [DNM] Remove ListIterator Remove ListIterator Sep 9, 2025
Comment on lines 51 to +52
<ListBase>
<ListIterator>
<ReferenceArrayFieldBase reference="tags" source="tag_ids">
<TagList />
</ReferenceArrayFieldBase>
</ListIterator>
<WithListContext loading={null} errorElement={null} offline={null} empty={null}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we use <ListBase emptyWhileLoading> instead of the WithListContext?

render={({ data }) => (
<Root className={className} {...sanitizeListRestProps(rest)}>
<RecordsIterator
data={data}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't you pass it to WithListContext instead?

@djhi djhi changed the title Remove ListIterator Rename and refactor ListIterator Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Development

Successfully merging this pull request may close these issues.

4 participants