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

ReferenceArrayField causing infinite loop when empty collection #3552

Closed
b-raines opened this issue Aug 20, 2019 · 2 comments
Closed

ReferenceArrayField causing infinite loop when empty collection #3552

b-raines opened this issue Aug 20, 2019 · 2 comments
Assignees
Labels

Comments

@b-raines
Copy link
Contributor

b-raines commented Aug 20, 2019

What you were expecting:
ReferenceArrayField loads associated records.

What happened instead:
ReferenceArrayField does initially load records, but gets caught in an infinite loop, calling setState.

Steps to reproduce:
Create Show view inside of a TabbedShowLayout (SimpleShowLayout also probably fine, but not tested) with a ReferenceArrayField containing an array of id's for associated records. When the view loads, it gets caught in infinite loop and will eventually lock up. This ONLY occurs when the collection is empty.

Related code:
Difficult to reproduce in sandbox, but can try to get something up if needed.

const UserShow = ({ record, ...props }) => (
  <Show
    {...props}
    title={<UserTitle />}
    aside={null}
    actions={<UserShowActions />}
  >
    <TabbedShowLayout>
      <Tab label="resources.users.tabs.user">
        <ReferenceArrayField
          label="Content Codes"
          reference="content/codes"
          source="content_code_ids"
          sort={{ field: 'code', order: 'ASC' }}
          allowEmpty
        >
          <SingleFieldList linkType="show">
            <ChipField source="code" />
          </SingleFieldList>
        </ReferenceArrayField>
      </Tab>
    </TabbedShowLayout>
  </Show>
)

Environment

  • React-admin version: v3.0.0.alpha-2
  • Last version that did not exhibit the issue (if applicable): v2.9.5
  • React version: 16.9.0
  • Browser: Chrome Version 76.0.3809.100
  • Stack trace (in case of a JS error):
Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.
    in ReferenceArrayField (at UserShow.js:57)
    in div (created by Labeled)
    in div (created by ForwardRef(FormControl))
    in ForwardRef(FormControl) (created by WithStyles(ForwardRef(FormControl)))
    in WithStyles(ForwardRef(FormControl)) (created by Labeled)
    in Labeled (created by WithStyles(Labeled))
    in WithStyles(Labeled) (created by Tab)
    in div (created by Tab)
    in span (created by Tab)
    in Tab (created by Context.Consumer)
    in translate(Tab) (at UserShow.js:44)
    in Route (created by TabbedShowLayout)
    in div (created by ForwardRef(CardContent))
    in ForwardRef(CardContent) (created by WithStyles(ForwardRef(CardContent)))
    in WithStyles(ForwardRef(CardContent)) (created by CardContentInner)
    in CardContentInner (created by WithStyles(CardContentInner))
    in WithStyles(CardContentInner) (created by TabbedShowLayout)
    in div (created by TabbedShowLayout)
    in TabbedShowLayout (created by Context.Consumer)
    in translate(TabbedShowLayout) (created by Context.Consumer)
    in withRouter(translate(TabbedShowLayout)) (at UserShow.js:43)
    in div (created by ForwardRef(Paper))
    in ForwardRef(Paper) (created by WithStyles(ForwardRef(Paper)))
    in WithStyles(ForwardRef(Paper)) (created by ForwardRef(Card))
    in ForwardRef(Card) (created by WithStyles(ForwardRef(Card)))
    in WithStyles(ForwardRef(Card)) (created by ShowView)
    in div (created by ShowView)
    in div (created by ShowView)
    in ShowView (created by Show)
    in Show (at UserShow.js:37)
    in UserShow (created by WithPermissions)
    in WithPermissions (created by Context.Consumer)
    in Route (created by ResourceRoutes)
    in Switch (created by ResourceRoutes)
    in ResourceRoutes (created by Resource)
    in Resource (at App.js:69)
    in Route (created by RoutesWithLayout)
    in Switch (created by RoutesWithLayout)
    in RoutesWithLayout (created by Context.Consumer)
    in div (created by Layout)
    in main (created by Layout)
    in div (created by Layout)
    in div (created by Layout)
    in Layout (created by WithStyles(Layout))
    in WithStyles(Layout) (created by Context.Consumer)
    in withRouter(WithStyles(Layout)) (created by ConnectFunction)
    in ConnectFunction (created by LayoutWithTheme)
    in ThemeProvider (created by LayoutWithTheme)
    in LayoutWithTheme (at Layout.js:17)
    in Unknown (created by WithStyles(Component))
    in WithStyles(Component) (created by Context.Consumer)
    in Route (created by CoreAdminRouter)
    in Switch (created by CoreAdminRouter)
    in div (created by CoreAdminRouter)
    in CoreAdminRouter (created by ConnectFunction)
    in ConnectFunction
    in ConnectFunction (created by Context.Consumer)
    in Route (created by CoreAdmin)
    in Switch (created by CoreAdmin)
    in Router (created by ConnectedRouter)
    in ConnectedRouter (created by Context.Consumer)
    in ConnectedRouterWithContext (created by ConnectFunction)
    in ConnectFunction (created by CoreAdmin)
    in TranslationProviderView (created by ConnectFunction)
    in ConnectFunction (created by CoreAdmin)
    in Provider (created by CoreAdmin)
    in CoreAdmin (at App.js:39)
    in App (at src/index.js:7)```
@b-raines b-raines changed the title ReferenceArrayField causing infinite loop w/ setState ReferenceArrayField causing infinite loop when empty collection Aug 20, 2019
@fzaninotto fzaninotto added the bug label Aug 21, 2019
@fzaninotto fzaninotto self-assigned this Aug 21, 2019
@fzaninotto
Copy link
Member

Confirmed. Will be fixed by #3550

@fzaninotto
Copy link
Member

fixed by #3550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants