react icon indicating copy to clipboard operation
react copied to clipboard

[BUG] Custom component unmounting

Open FractalStranger opened this issue 3 years ago • 7 comments

Hi,

I have a React18 project and wanted to make custom react-formio component (code below) but this.container.unmount in detachReact method shows this warning:

Warning: Attempted to synchronously unmount a root while React was already rendering. React cannot finish unmounting the root until the current render has completed, which may lead to a race condition.

is there any way to unmount the element without the warning? (And is react-formio compatible with React 18 overall?)

Thanks.

Code:

export default class Grid extends ReactComponent {
  ...
  ...

  attachReact(element) {
    this.container = createRoot(element)
    return this.container.render(
      <HistoryRouter history={history}>
        <GridComponent {...{ ...this }} />
      </HistoryRouter>
    )
  }

  detachReact(element) {
    if (element) {
      this.container.unmount() // this creates the race condition warning
    }
  }
}

Environment

  • Hosting type
    • [ ] Form.io
    • [x] Local deployment
      • Version:
  • Formio.js version: 5.0.0-m.3
  • Frontend framework: React 18

FractalStranger avatar Nov 15 '22 12:11 FractalStranger

Do u have any example of custom component with react typescript if yes please share.

aryanisml avatar Nov 16 '22 08:11 aryanisml

Typescript? Does react-formio support Typescript? It doesn't seem so.

Here is the code of custom component: https://jsfiddle.net/kv0tq9p8/

FractalStranger avatar Nov 16 '22 14:11 FractalStranger

Hey I am a newcomer in this project and I would like to contribute

govind15496 avatar Jan 05 '23 13:01 govind15496

Hi,

I have a React18 project and wanted to make custom react-formio component (code below) but this.container.unmount in detachReact method shows this warning:

Warning: Attempted to synchronously unmount a root while React was already rendering. React cannot finish unmounting the root until the current render has completed, which may lead to a race condition.

is there any way to unmount the element without the warning? (And is react-formio compatible with React 18 overall?)

Thanks.

Code:

export default class Grid extends ReactComponent {
  ...
  ...

  attachReact(element) {
    this.container = createRoot(element)
    return this.container.render(
      <HistoryRouter history={history}>
        <GridComponent {...{ ...this }} />
      </HistoryRouter>
    )
  }

  detachReact(element) {
    if (element) {
      this.container.unmount() // this creates the race condition warning
    }
  }
}

Environment

  • Hosting type

    • [ ] Form.io

    • [x] Local deployment

      • Version:
  • Formio.js version: 5.0.0-m.3

  • Frontend framework: React 18

I wonder if you can share your GridComponent code? I am trying to implement it myself but I am not sure how to start.

mtruon11 avatar Jul 31 '23 20:07 mtruon11

@FractalStranger did you figure any way to get around this?

lotorvik avatar Sep 11 '23 11:09 lotorvik

@FractalStranger Hello, did you find someway to figure this out yet? Same issue I also encoutered.

YoungDriverOfTech avatar Apr 26 '24 05:04 YoungDriverOfTech