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

Add useOpaqueIdentifier Hook #17322

Merged
merged 7 commits into from Apr 7, 2020
Merged

Add useOpaqueIdentifier Hook #17322

merged 7 commits into from Apr 7, 2020

Commits on Apr 3, 2020

  1. Add useOpaqueIdentifier Hook

    We currently use unique IDs in a lot of places. Examples are:
      * `<label for="ID">`
      * `aria-labelledby`
    
    This can cause some issues:
      1. If we server side render and then hydrate, this could cause an
         hydration ID mismatch
      2. If we server side render one part of the page and client side
         render another part of the page, the ID for one part could be
         different than the ID for another part even though they are
         supposed to be the same
      3. If we conditionally render something with an ID ,  this might also
         cause an ID mismatch because the ID will be different on other
         parts of the page
    
    This PR creates a new hook `useUniqueId` that generates a different
    unique ID based on whether the hook was called on the server or client.
    If the hook is called during hydration, it generates an opaque object
    that will rerender the hook so that the IDs match.
    lunaruan authored and acdlite committed Apr 3, 2020
    Copy the full SHA
    70a8db8 View commit details
    Browse the repository at this point in the history
  2. Remove $$typeof from client-generated id

    Not used anywhere
    acdlite committed Apr 3, 2020
    Copy the full SHA
    55c1b1c View commit details
    Browse the repository at this point in the history
  3. Return string in DEV

    The wrapper object is only used to warn if the value is accessed.
    
    This means `typeof` will be different between dev and prod.
    acdlite committed Apr 3, 2020
    Copy the full SHA
    bd02e23 View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    68ff9cb View commit details
    Browse the repository at this point in the history
  5. Use pushEffect instead of effect hook

    Effect is only need on initial mount, and only when hydrating, so we can
    optimize this a bit.
    acdlite committed Apr 3, 2020
    Copy the full SHA
    cd64a0f View commit details
    Browse the repository at this point in the history

Commits on Apr 6, 2020

  1. Remove deep import of getIsRendering internal

    Shuffles boundary between host config and renderer so that this deep
    import is no longer necessary.
    acdlite committed Apr 6, 2020
    Copy the full SHA
    2d9cb27 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    815042f View commit details
    Browse the repository at this point in the history