Skip to content

use createRoot when possible for rendering pin components - #319

Merged
oshi97 merged 7 commits into
feature/mapbox-componentfrom
dev/createRoot-with-fallback
Oct 28, 2022
Merged

oshi97 merged 7 commits into
feature/mapbox-componentfrom
dev/createRoot-with-fallback

Conversation

@oshi97

@oshi97 oshi97 commented Oct 27, 2022 •

Copy link
Copy Markdown
Contributor

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

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
Comment thread tsconfig.json
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"module": "esnext",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@coveralls

coveralls commented Oct 27, 2022 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.3%) to 84.423% when pulling 72f05ed on dev/createRoot-with-fallback into 731c9bd on feature/mapbox-component.

@oshi97
oshi97 marked this pull request as ready for review October 28, 2022 14:15
@oshi97
oshi97 requested a review from a team as a code owner October 28, 2022 14:15
@oshi97
oshi97 requested review from nmanu1 and tatimblin October 28, 2022 15:22

@tatimblin tatimblin left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 (percy failed but no snapshot looks broken, maybe rerun?)

Comment thread tests/tsconfig.json Resolved
@oshi97
oshi97 merged commit 0d78e7e into feature/mapbox-component Oct 28, 2022
@oshi97
oshi97 deleted the dev/createRoot-with-fallback branch October 28, 2022 16:43
oshi97 added a commit that referenced this pull request Nov 4, 2022
@nmanu1 nmanu1 mentioned this pull request Nov 15, 2022
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

Successfully merging this pull request may close these issues.

4 participants