Skip to content

Catch invalid dom nesting on initial render #2839

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

Closed
brigand opened this issue Jan 12, 2015 · 2 comments
Closed

Catch invalid dom nesting on initial render #2839

brigand opened this issue Jan 12, 2015 · 2 comments

Comments

@brigand
Copy link
Contributor

brigand commented Jan 12, 2015

Currently, you get an error when react tries to update the DOM, and things aren't as expected. Early errors are much better, so in development React should give clear errors based on valid HTML structures.

For example, the select element has 1 valid child: option. The option element has 1 valid child: text node. Forms have one invalid deep child: form; and tables have a quite a few rules.

The suggested error format:

InvariantViolation: at FooComponent <select> may only have <option> children, but 
encountered: option, option, select, option, option

Forms. The element:N means displayName:childIndexIfNotZero.

InvariantViolation at FooComponent: <form> may not have any deep <form> children.
Culprit is form > div > form

InvariantViolation at FooComponent: <form> may not have any deep <form> children.  
Culprit is form -> div > div:3 > section:2 > BarComponent > div > form:1

Tables

InvariantViolation at FooComponent: <table> may only have <caption>, <thead>, <tfoot>, 
and <tbody> children, but encountered thead, tr*100

InvariantViolation at FooComponent: <table> may only have one <thead> child, but 
encountered thead, thead, tr*100

InvariantViolation at FooComponent: <table> may only have one <thead> child, but 
encountered thead, thead, tr*100

The less frequently encountered situations can be pushed to a different release, but I think it's important to have. These are bad habits that people are used to, because they're allowed in most other situations.

These are examples of people who have run into this problem.

select/option

nested forms:

tables

@syranide
Copy link
Contributor

#101 and #101 (comment)

As I mention, I think it's quite easily and realistically solvable (for DEV at least).

cc @zpao

@sophiebits
Copy link
Collaborator

This happened.

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

No branches or pull requests

3 participants