Skip to content

Server Rendering #387

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

Closed
wants to merge 13 commits into from
Closed

Server Rendering #387

wants to merge 13 commits into from

Conversation

mpeyper
Copy link
Member

@mpeyper mpeyper commented Jun 8, 2020

What:

This is an early look at what I'm thinking for #68.

It adds the ability to test hooks in different environments by allowing different renderers to be used. The library will ship with 3 renderers:

  • @testing-library/react-hooks/native (react-test-renderer)
  • @testing-library/react-hooks/dom (react-dom)
  • @testing-library/react-hooks/server (react-dom/server)

Additionally, the main import for the package (@testing-library/react-hooks) will autodetect which of react-dom or react-test-renderer is installed and select the appropriate renderer to use.

Why:

Currently there was no way to test how a hook would behave when using rendering server side rendering.

#418 has also raised the issue that refs are not being set when using react-test-renderer so this would also see a solution for users requiring that but being able to use react-dom to render instead.

How:

By abstracting the rendering, rerendering and unmounting behaviour away from the core functionality, it was possible to provide thin renderer implementations that can leverage the same underlying logic. This opened the door to allowing DOM users to use use the existing renderer they have installed instead of having to install react-test-renderer specifically for this library.

I would like to make it easier for other libraries to implement their own renderer on top of our core logic as well to make more use cases easier to implement (although I don't think we will ever ship more than the 3 renderers in this package). This would likely be using a @testing-library/react-hooks/custom import, rather than drilling into the lib/core module.

Docs are still to come and tests are not complete (but pretty close).

Checklist:

  • Documentation updated
  • Tests
  • Ready to be merged
  • Added myself to contributors table

@codecov
Copy link

codecov bot commented Jun 8, 2020

Codecov Report

Merging #387 into master will decrease coverage by 10.49%.
The diff coverage is 85.45%.

Impacted file tree graph

@@             Coverage Diff              @@
##            master     #387       +/-   ##
============================================
- Coverage   100.00%   89.50%   -10.50%     
============================================
  Files            4       13        +9     
  Lines           94      162       +68     
  Branches        15       22        +7     
============================================
+ Hits            94      145       +51     
- Misses           0       16       +16     
- Partials         0        1        +1     
Impacted Files Coverage Δ
src/core/async-utils.js 100.00% <ø> (ø)
src/custom/index.js 0.00% <0.00%> (ø)
src/custom/pure.js 0.00% <0.00%> (ø)
src/index.js 0.00% <0.00%> (-100.00%) ⬇️
src/pure.js 0.00% <0.00%> (-100.00%) ⬇️
src/server/pure.js 89.65% <89.65%> (ø)
src/core/cleanup.js 100.00% <100.00%> (ø)
src/core/index.js 100.00% <100.00%> (ø)
src/dom/index.js 100.00% <100.00%> (ø)
src/dom/pure.js 100.00% <100.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d1f13b...837105e. Read the comment docs.

@mpeyper
Copy link
Member Author

mpeyper commented Nov 10, 2020

I'm going to close this as it's getting very far behind master and there hasn't been much interest raised in it. If anyone is keen for it, or functionality like it, comment here and we might pick it up again.

@mpeyper mpeyper closed this Nov 10, 2020
@nickserv nickserv deleted the pr/server-rendering branch November 30, 2020 08:24
@mpeyper mpeyper mentioned this pull request Dec 3, 2020
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.

1 participant