Repository navigation
use createRoot when possible for rendering pin components - #319
Merged
Merged
Conversation
This PR uses a dynamic imports with a .catch fallback for when
react-dom/client does not exist.
MapboxMap code had to be tweaked due to differences between ReactDOM.render
and ReactDOM.createRoot().render(). Namely, createRoot() does not modify the
container element unless it already exists on the physical page.
This means that we can't call document.creatElement('div'), use createRoot,
and THEN attach it to the mapbox map. Instead, we have to attach the div to the
map first.
This also seems it make it more difficult to unit test, my guess would be because
createRoot does not do anything on the server. For now I use some jest.mocks to
ensure the right methods are being called in the right environments.
TEST=manual,auto
oshi97
commented
Oct 27, 2022
| @@ -1,5 +1,6 @@ | |||
| { | |||
| "compilerOptions": { | |||
| "module": "esnext", | |||
Contributor
Author
There was a problem hiding this comment.
this is needed so vscode doesn't complain about us doing dynamic imports without setting module to something like "esnext" or "commonjs", since vscode only knows about this tsconfig and not the cjs and esm ones which already have module set
oshi97
marked this pull request as ready for review
October 28, 2022 14:15
tatimblin
reviewed
Oct 28, 2022
tatimblin
approved these changes
Oct 28, 2022
nmanu1
reviewed
Oct 28, 2022
oshi97
added a commit
that referenced
this pull request
Nov 4, 2022
…)" This reverts commit 0d78e7e.
Merged
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.
This PR uses a dynamic imports with a .catch fallback for when react-dom/client does not exist.
MapboxMap code had to be tweaked due to differences between ReactDOM.render and ReactDOM.createRoot().render(). Namely, createRoot() does not modify the container element unless it already exists on the physical page. This means that we can't call document.creatElement('div'), use createRoot, and THEN attach it to the mapbox map. Instead, we have to attach the div to the map first.
This also seems it make it more difficult to unit test, my guess would be because createRoot does not do anything on the server. For now I use some jest.mocks to ensure the right methods are being called in the right environments.
TEST=manual,auto
storybook can start up (react 17)
test site can display custom pin in both react 17 and 18