Conversation
|
Build successful! 🎉 |
5 tasks
Merged
|
Build successful! 🎉 |
dannify
approved these changes
Aug 21, 2020
|
Build successful! 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #959
Related: #760, #835, #899, #842
This adds an
SSRProvidercomponent that must be used when using React Spectrum or React Aria in a server rendered environment. This lives within the@react-aria/ssrpackage, and we'll also re-export it from the@adobe/react-spectrummono-package.useIdstill lives within@react-aria/utilsthough for back compatibility, so we had to add a dependency on@react-aria/ssrthere.SSRProvider provides a context to the rest of the app containing two numbers: a prefix number, and a current id. By default, when no
SSRProvideris available, the prefix is set to a random number. This allows multiple instances of React Spectrum/React Aria to be on the page at once in order to prevent potential id clashes. However, when in an SSR environment we must set this prefix to a known value that will be consistent between the client and server. Therefore, in SSR, only a single copy of React Spectrum/React Aria will be supported. This seems like a reasonable tradeoff.The second number is the current auto incrementing id that is incremented whenever
useIdis called. However, rather than being a global value, it's now also in the context. This ensures that the server resets the value for each request, which keeps the ids consistent between the client and server.The one case where it's possible to get mismatches is with async-loaded components. While
React.lazydoesn't support SSR yet, there are other libraries that implement this. If the loading order of these async boundaries were different between the client and server, we could get id mismatches. This can be solved by wrapping each async component in an additional<SSRProvider>. Doing this resets the current id counter, and increments the prefix. This way, the prefix is incremented outside the async boundary, and the ids within the async component are guaranteed to be unique.Finally, I had to update the way the SSR tests ran because they were not capturing the mismatching ids in all cases. That was because Jest resets the environment before each test, so the ids were starting over from zero each time. Now we run a single server to do SSR for all tests over HTTP, and the tests just make requests to it. That better simulates a real long-running server environment.