Skip to content

Commit

Permalink
🐛 [open-formulieren/open-forms#4699] Only render AddressNL component …
Browse files Browse the repository at this point in the history
…when not hidden

The AddressNL component should only be rendered when it's not hidden. Otherwise, the attach function will call `createRoot` with an argument that isn't a DOM element.

So the creating of the root and, therefor, the rendering of the React component cannot be done.
If the reactRoot doesn't exist, then it also doesn't (and cannot) be unmounted. So this is also something that shouldn't happen when the component is hidden.

This works fine when the component is hidden/shown using form logic, as the `hidden` property will be updated.
  • Loading branch information
robinmolen committed Jan 27, 2025
1 parent 49bd7cb commit bf05e4a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/formio/components/AddressNL.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ export default class AddressNL extends Field {
addressNLContainer: 'single',
});
return super.attach(element).then(() => {
this.reactRoot = createRoot(this.refs.addressNLContainer);
this.renderReact();
if (!this.component?.hidden) {
this.reactRoot = createRoot(this.refs.addressNLContainer);
this.renderReact();
}
});
}

destroy() {
const container = this.refs.addressNLContainer;
if (container) this.reactRoot.unmount();
if (!this.component?.hidden && container) this.reactRoot.unmount();
super.destroy();
}

Expand Down Expand Up @@ -146,6 +148,9 @@ export default class AddressNL extends Field {
}

renderReact() {
if (this.component?.hidden) {
return;

Check warning on line 152 in src/formio/components/AddressNL.jsx

View check run for this annotation

Codecov / codecov/patch

src/formio/components/AddressNL.jsx#L152

Added line #L152 was not covered by tests
}
const required = this.component?.validate?.required || false;
const initialValues = {...this.emptyValue, ...this.dataValue};

Expand Down

0 comments on commit bf05e4a

Please sign in to comment.