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

[Fizz] Disallow complex children in <title> elements #24679

Merged
merged 4 commits into from Jun 7, 2022

Commits on Jun 7, 2022

  1. [Fizz] Disallow complex children in <title> elements

    <title> Elements in the DOM can only have Text content. In Fizz if more than one text node is emitted an HTML comment node is used as a text separator. Unfortunately because of the content restriction of the DOM representation of the title element this separator is displayed as escaped text which is not what the component author intended.
    
    This commit special cases title handling, primarily to issue warnings if you pass complex children to <title>. At the moment title expects to receive a single child or an array of length 1. In both cases the type of that child must be string or number. If anything more complex is provided a warning will be logged to the console explaining why this is problematic.
    
    There is no runtime behavior change so broken things are still broken (e.g. returning two text nodes which will cause a separator or using Suspense inside title children) but they should at least be accompanied by warnings that are useful.
    
    One edge case that will now warn but won't technically break an application is if you use a Component that returns a single string as a child of title. This is a form of indirection that works but becasue we cannot discriminate between a Component that will follow the rules and one that violates them the warning is issued regardless.
    gnoff committed Jun 7, 2022
    Copy the full SHA
    125ec3a View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    1ea51af View commit details
    Browse the repository at this point in the history
  3. lints

    gnoff committed Jun 7, 2022
    Copy the full SHA
    1810bd5 View commit details
    Browse the repository at this point in the history
  4. fix bugs

    gnoff committed Jun 7, 2022
    Copy the full SHA
    d97aacc View commit details
    Browse the repository at this point in the history