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
Treeshaking Removes Critical React DOM Code #3168
Comments
Thanks for spotting, this is very helpful, I think I see what is going on. Will dig into this soon. |
I think the long and short is that I did not consider that labeled statements do act as a means of optional control flow and therefore errors inside labeled statements need to be handled similar to errors inside if-statement branches. |
Awesome! (I just learned today that labeled statements exist. 🙃 Neat!) Thanks for looking into this. |
😉 I think I'll be able to release a fix tomorrow. |
A little thank you for creating the issue (always helps to know I'm not going mad.) I'd noticed it too but was trying to figure out whether it was rollup or sentry in this instance. The fix for the time being of course is to remain on 1.23.1 for now - thanks also for addressing the issue so quickly :) |
Fix at #3170. Interestingly, fixing this made the logic simpler rather than more complicated, so I snuck in another feature as well which is to remove unused labels. |
BTW I am very happy that there are people compiling React using the latest versions of Rollup. There is a long-standing PR to finally get React to upgrade to the 1.x versions of Rollup but apparently it is not moving forward, which makes me quite sad: facebook/react#15037 |
I just came across this issue after running into something similar myself with React DOM breaking in 1.24 which isn't fixed in 1.25. I'm not sure if it's another case of this issue or something different, but it appears to be related to code being treeshaken inside the |
A diff between the bundled code with 1.23 and 1.25 would be helpful. By now I have an idea that there might be another situation I may have handled wrongly which is a do..while loop containing a conditional break and an unconditional throw or return, but there might be more, which is why I am very interested in this. Will probably not be able to put out something new before Monday, though. |
I managed to dig into the ReactDOM bugs with 1.25 and it looks like it's different behaviour from this issue, so I opened a new one: #3177 |
How Do We Reproduce?
A minimal reproduction repo can be found here: https://github.com/spencer516/react-rollup-bug
(I could not recreate the same behavior in the rollup repl — not sure if it's on 1.24 or not).
Expected Behavior
When using the Production/Minified version of React DOM in an app that is bundled and treehsaken (treeshook?) by Rollup, I would expect the application to behave identically before and after the tree shaking. Specifically to React DOM: I expect it to insert the elements I render.
Actual Behavior
Rollup is removing small, but critical, parts of React DOM causing the application not to render and not to throw any runtime errors. The parts that are removed appear to be related to all of the DOM Node Inserting here.
A few notes:
v1.23.1
and earlier./react-dom/cjs/react-dom.production.min.js
)To isolate the difference of treehsaking React DOM in 1.23 vs 1.24, I built my app in both version, ran Prettier to format the minified code, and ran a diff. The additional code removed can be seen here: spencer516/react-rollup-bug@dist-1.23...dist-1.24
I suppose it's possible this is also a React DOM bug (perhaps their minified code is invalid in some way?) — I'm happy to open an issue there, too, if it helps.
The text was updated successfully, but these errors were encountered: