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

React DOMException when setting undefined #1036

Closed
chester23491 opened this issue Jan 4, 2023 · 3 comments · Fixed by #1045
Closed

React DOMException when setting undefined #1036

chester23491 opened this issue Jan 4, 2023 · 3 comments · Fixed by #1045
Assignees
Labels
🐛 Bug Something isn't working 🧑‍💻 Technical Design System Stencil based implementation

Comments

@chester23491
Copy link

Uncaught DOMException in React

We are getting a Uncaught DOMException in React, when we are setting undefined in the Baloise components at runtime.

Message:

Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
    at removeChild (http://localhost:3000/static/js/bundle.js:24925:22)
    at commitDeletionEffectsOnFiber (http://localhost:3000/static/js/bundle.js:37642:19)
    at commitDeletionEffects (http://localhost:3000/static/js/bundle.js:37591:9)
    at recursivelyTraverseMutationEffects (http://localhost:3000/static/js/bundle.js:37866:13)
    at commitMutationEffectsOnFiber (http://localhost:3000/static/js/bundle.js:37953:13)
    at recursivelyTraverseMutationEffects (http://localhost:3000/static/js/bundle.js:37880:11)
    at commitMutationEffectsOnFiber (http://localhost:3000/static/js/bundle.js:37939:13)
    at recursivelyTraverseMutationEffects (http://localhost:3000/static/js/bundle.js:37880:11)
    at commitMutationEffectsOnFiber (http://localhost:3000/static/js/bundle.js:37900:13)
    at recursivelyTraverseMutationEffects (http://localhost:3000/static/js/bundle.js:37880:11)
The above error occurred in the <Text> component:
    at bal-text
    at m (http://localhost:3000/static/js/bundle.js:2384:7)
    at BalText
    at bal-card
    at m (http://localhost:3000/static/js/bundle.js:2384:7)
    at BalCard
    at main
    at bal-app
    at m (http://localhost:3000/static/js/bundle.js:2384:7)
    at BalApp
    at App (http://localhost:3000/static/js/bundle.js:1452:76)

Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.

Detailed description

const [foo, setFoo] = React.useState<string | undefined>("foo");
return (
<BalText>{foo}</BalText>
<BalButton
  onClick={
    // setting is not working -> leads to Uncaught DOMException
    () => setFoo(undefined)
  }
>
  Set Undefined
</BalButton>
);

Steps to reproduce the issue

  1. Add the code snipplet into your system or clone the following fork with branch: create example of setting component undefined baloise/design-system-examples#6
  2. Open browser console
  3. Click on "Set Undefined", page is going blank, check console

Additional information

  • Production bug for BAT project
@chester23491 chester23491 added the 🐛 Bug Something isn't working label Jan 4, 2023
@hirsch88 hirsch88 added the 🧑‍💻 Technical Design System Stencil based implementation label Jan 5, 2023
@hirsch88
Copy link
Member

hirsch88 commented Jan 5, 2023

Hi @chester23491 please use the state in the text like that

<BalText><>{foo}</></BalText>

because otherwise you are pushing an undefined to a child directly.

@hirsch88 hirsch88 self-assigned this Jan 5, 2023
@chester23491
Copy link
Author

Hey @hirsch88, thank you for the quick response. Did you try it out? I'm getting still this error. The error exist in all react components. Also when we set string empty I'm are getting this error.

@chester23491
Copy link
Author

Hi @hirsch88

Thank you for your time. I tried to reproduce the issue in the ionic-framework react test app (https://github.com/ionic-team/ionic-framework/tree/main/packages/react/test-app). Setting the components empty or undefined is working fine. I was not able to reproduce it there.

const Main: React.FC<MainProps> = () => {
  const [foo, setFoo] = React.useState<string | undefined>('foo');

  return (
    <IonPage>
      <IonText>{foo}</IonText>
      <IonButton onClick={() => setFoo(undefined)}>Set Undefined</IonButton>
      <IonButton onClick={() => setFoo('')}>Set Empty</IonButton>
      <IonButton onClick={() => setFoo('Bar')}>Set Bar</IonButton>
      <IonButton onClick={() => setFoo(' ')}>Set Whitespace</IonButton>
    </IonPage>
  );
};

Can you please update as discussed the react-component-lib?

Regards,
Charles

hirsch88 added a commit that referenced this issue Jan 10, 2023
…on-when-setting-undefined

fix(react): handle empty nodes. Closes #1036
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working 🧑‍💻 Technical Design System Stencil based implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants