-
Notifications
You must be signed in to change notification settings - Fork 776
fix(render, tailwind): The renderAsync utility and the Tailwind component failing on the edge for next 14 #1079
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
Merged
Conversation
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
… and prioritize the other functions instead of it
this was mostly to fix another issue that was arising after fixing #1054 the problem is that next kind of stubs the renderToString and renderToStaticMarkup into throwing the errors that they were having, sadly the only way to get around this was to implement a custom simple method that would render the most stub HTML possible just for tailwind to generate their classes
…for renderAsyncjjj
…ings will run properly also add a test to each environment with the legacy stubs that next 14 adds
DamienDeloubes
approved these changes
Dec 13, 2023
bukinoshita
reviewed
Dec 13, 2023
f47519c
to
47efebf
Compare
bukinoshita
reviewed
Dec 14, 2023
bukinoshita
reviewed
Dec 14, 2023
bukinoshita
approved these changes
Dec 14, 2023
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 introduces two changes, one to fix the
renderAsync
utility to run on the edge,and the other to fix the Tailwind component also failing on the edge.
The
renderAsync
fixAfter I investigated a bit on Next's code and found that they stub the
renderToString
and
renderToStaticMarkup
functions to avoid their internal use of them becauseit seems like it is going to be deprecated.
So to not have any problems with this I added a few tests that stub both these functions
on the
renderAsync
function's tests to make sure it runs fine, besides also removingthe fallback on the
renderToStaticMarkup
. I've also tested thiswith Next 13 and it works well meaning there is no problem with the removal of renderToStaticMarkup.
I also used the
renderToStaticNodeStream
instead ofrenderToPipeableStream
sincethat function is made for rendering static content like
renderToStaticMarkup
.The fix for the Tailwind component
For the Tailwind component due to the strategy of rendering the HTML just to then generate
Tailwind's global styles we used
renderToStaticMarkup
but that caused problemson the edge as well and probably on other environments and situations too.
After thinking a lot about this, thinking if I could use the async React rendering functions
for this, and getting to the conclusion I needed to write the simplest we can get away
with mock renderer for React just to get the class names onto tailwind all at once I could.
This render utility just loops through the elements recursively (similarly to what the Tailwind component
already does) and then converts everything into HTML by directly mapping props into attributes,
(converting objects into JSONs as well). This also gave us a small performance boost but not very noticeable
I also wrote a simple unit test that tries out a few things to see if the renderer can take them as well,
like rendering components, dealing with children and fragments.
Closes #1054