Skip to content
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

fix(emotion): fix render loop #78

Merged
merged 3 commits into from
Apr 26, 2023

Conversation

RobinClowers
Copy link
Contributor

@RobinClowers RobinClowers commented Nov 22, 2022

This solves the render loop when loading the emotion example. As far as I can see, we only need to re-inject the styles on the client if the top level component gets unmounted (because that removes the document head, where the styles are).

My original PR had removed all of the code related to this re-injection, but we do need it for that case.

Original description below.

However, when you trigger the catch boundary on the client, you loose all the styles, since the entire document is re-rendered. This same problem exists in the Chakra example, but you can't easily tell, since there is no link you can follow to trigger the error boundary on the client.

I finally understand what the code I was removed was trying to do (add the styles back in after re-mounting the document), but it was broken.

I'm not sure what the correct fix is, but I think this is better than the broken example we have now. I will try to spend some more time on this soon, to see if I can find a complete solution.

Fixes: #1

@MichaelDeBoey MichaelDeBoey changed the title Fix emotion example render loop fix(emotion): fix render loop Nov 22, 2022
Copy link
Member

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

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

I updated this in #40 to be in line with what @chaance did in #35
Since I'm not familiar with emotion, I'll let him have a look at this one

@RobinClowers
Copy link
Contributor Author

@MichaelDeBoey Thanks for the quick response! I looked at this a bit more and I think I found a more correct solution that works with top level error and catch boundaries as well.

@mi-na-bot
Copy link

Since this is an example for end users to copy, it would be helpful to add the correct eslint annotation to suppress the "exhaustive dependencies" warning for that one line.

Copy link

@coreyward coreyward left a comment

Choose a reason for hiding this comment

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

I have no permissions here, but I just want to confirm that this change works for me. I would love to see this applied since the example is misleading/broken as it stands!

@RobinClowers
Copy link
Contributor Author

Agreed, this could probably be improved further, but it works, and the example is currently broken, so it seems like a clear win. @chaance can you find time to take a look at this?

emotion/app/root.tsx Outdated Show resolved Hide resolved
@jmborden
Copy link

@RobinClowers Thanks for this! Funny to bump into each other again in such a random place :D

@RobinClowers
Copy link
Contributor Author

@jmborden 🥂 sure thing!

@RobinClowers
Copy link
Contributor Author

I've pushed up the ref change so the relink won't happen twice with strictmode in dev and got rid of the lint disable. I think this should be merged, since it fixes the issue, if we want to update to react 18, that could be a separate PR.

@RobinClowers
Copy link
Contributor Author

@chaance anything preventing this from merging?

@github-actions
Copy link
Contributor

This PR has been automatically marked stale because we haven't received a response from the original author in a while 🙈. This automation helps keep the issue tracker clean from issues that are not actionable. Please reach out if you have more information for us or you think this issue shouldn't be closed! 🙂 If you don't do so within 7 days, this PR will be automatically closed.

@github-actions github-actions bot added the needs-response We need a response from the original author about this issue/PR label Apr 22, 2023
@RobinClowers RobinClowers requested a review from chaance April 22, 2023 23:42
@github-actions github-actions bot removed the needs-response We need a response from the original author about this issue/PR label Apr 23, 2023
emotion/app/root.tsx Outdated Show resolved Hide resolved
emotion/app/root.tsx Outdated Show resolved Hide resolved
@MichaelDeBoey MichaelDeBoey removed the request for review from chaance April 25, 2023 14:15
Copy link
Member

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

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

Be sure to run ESLint/Prettier on your files

emotion/app/root.tsx Outdated Show resolved Hide resolved
Even in strict mode, plus we don't have to disable the lint warning.
@RobinClowers
Copy link
Contributor Author

Be sure to run ESLint/Prettier on your files

Sorry about that, I committed your suggestions through github. I just fixed this and squashed the fix into the previous commit. Thanks for looking at this!

Copy link
Member

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

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

Awesome!
Thanks for taking the time to update this example @RobinClowers! 🙏

If you would like to also create a PR to update this one to React 18, we'd be happy to accept a PR for that as well

@MichaelDeBoey MichaelDeBoey merged commit 6ce8506 into remix-run:main Apr 26, 2023
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.

Emotion example is poorly performant, re-rendering over 50 times a second
7 participants