-
Notifications
You must be signed in to change notification settings - Fork 29
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
Improvement on externalize React for React usages inside bundle codes #211
Comments
Hello. I never heard about the "React Developer Tools", so here are my questions regarding this issue you mentioned.
Thanks |
Hi, thanks for the prompt reply! My replies below:
React DevTools is a Chrome extension by Meta (developers of React) for developers to inspect/debug/profile websites made using React. You can do stuff like viewing the node structure/components of the page and their props, look at what part of the page is taking the most time to load, etc.
There are no observable effects to a normal user using Source Academy. The point of concern is mainly that this extension shows this status change, which is unusual behaviour (other modules work fine). The focus of this GitHub issue is to investigate why this occurs and whether this may or may not be indicative of some underlying issue (e.g. performance problem, the way we execute modules, etc.).
Thanks, that could be a potential cause of the status change of the extension. I am not too familiar with the implementation of Unity Academy so I was not sure if there was any React component involved, but after your reply, it seems probable and worth investigating.
That is fair, we don't have to fix it immediately, especially if you don't have the bandwidth to do so. We can always pick this up another time; at least we try to understand what is happening and the root cause of it first. Perhaps it is something so trivial the effort to fix it is just not worth it.
It is possible. I am not too familiar either. Perhaps @leeyi45 can chip in? Thanks! |
Hello. Thanks for your explanation. From my view of my own module's code, my module creates a separated (covering the page) React component and inserting this new component directly in the current page to display Unity Academy, and this is related to the whole workflow and initialization of my module and Unity Academy Webgl frontend. Since this is working fine for functionality, and for now I haven't feel any observable efficiency problems (Unity Academy frontend has its internal optimizations such as auto-sleeping), so if you also think so, this problem may be not very urgent to fix. Also, since my code for creating that new React component and inserting it into the page is common in usual React development (although this is not usual in SA modules that the fact is that other modules only has Tabs which are inserted by JS-Slang not module). So I think that possibility we should focus on how to change the module deployment and build system to solve this. Since if other modules in the future also requires uses their own React component (when Tab is not sufficient for functionality), fixing this issue by changing building system will make the module building system more flexible for these new requirements. Unity Academy is using So personally I think this problem is more likely related to current module building system, and it is uncovered only by my module because unlike other modules, my module requires a new feature to use (the feature of having a separated React component besides Tab) |
So maybe we should close this issue and open a new issue regarding: Defining new React components in bundle scripts and then using If this get fixed, in the future other modules can also use separated React component if needed without unusual warnings. To fully make sure that this problem is related to "React components inside bundles scripts" instead of other things in Unity Academy module, you can try creating a totally empty SA module with an empty react component inside bundle script, then use |
We need to investigate whether that is really the cause of this issue. Either way, I don't think we should close this issue anytime soon. We'll probably just rename it and assign the relevant people once we finish investigating. |
@larrywang0701 does this issue occur with the other modules? Module code is compiled directly to production, so even if you use the frontend in development mode, the loaded tabs will be React in production mode. This may be the reason for the indication Maybe a way to test this is to change the script that builds the modules The option is located under |
You need to ask @RichDom2185, he found out the issue. If this only happen in my Unity Academy module, I think this may related to improper compilation behavior for the "React components" directed inside "bundle" scripts (NOT tabs). You mentioned that Tabs are directly compiled to production, but how about other React components inside bundles (apart from Tabs)?
Someone can perform this test to confirm the problem source. Better directly under sourceacademy.org (production environment frontend) instead of locally. So maybe the test module need to temporarily merge into production and then remove once test is finished. |
Apologies, I missed the part where you stated that the issue is specific to the unity academy. A casual scroll through the built bundle for unity academy seems to indicate that this is the case. Is there a reason why this code has to be in the bundle? |
So personally instead of changing the code of Unity Academy, I think that we should try to make the module building system supports the feature of "adding custom React components inside bundles", since Tabs are not 100% sufficient under all cases (in the case of Unity Academy, Tabs are not sufficient), so in the future if other modules also require using their own React component inside bundle script, their functions won't be limited by the limitation of module building system. And also, since currently it's not very easy for bundles and tabs to exchange data (exchange data only by that context state variable), so if this limitation of "no React inside bundles" is removed, I think module programmers can also directly access and control tab components inside bundles, which will make their module more easy and flexible to make.
Tabs are too small in size for Unity Academy to display well (Unity Academy requires full-page display for best experience) and also, Unity Academy requires a canvas that always exists in the html document to work correctly, where Tabs will dismount and all html elements are destroyed when user switch away from Tabs If it's necessary to make changes to Unity Academy's source, please tell me and I'll try move that separated React component from bundle to Tab source file, then test everything again to see whether it works well since such a change is a major change to my module, and I should do it by myself. But still, I think we should make the module building system support new requirements, not removing new requirements because of the limitations of building system. |
I won't be so fast as to recommend that bundles and tabs adopt the changes you've suggested, but I agree that there is a need for more customization with tabs and persistent module contexts. If unity academy is working fine right now aside from the React development tools integration nothing needs to be changed. I agree with supporting new requirements, just trying to minimize the amount of changes needed. I am unsure on how your custom component gets rendered, but I have a feeling that it won't work with React externalized. I don't think there's a (a straightforward, at least) way to get React imported into bundle code without bundling it with that code. |
Inside bundle script: |
If you want you can try marking React as external for bundles, but like I said, I think by creating the element and rendering it this way you're using the instance of React bundled with your code. |
Just to clarify that in order to achieve this, we have to modify the overall module building system instead of Unity Academy module's source code right? Or it can be solved just by changing Unity Academy's code? If it's the second, I can try make changes to my own module. But currently I'm not familiar with module building system so maybe I can't help much with improving building system at this moment.
Yes, since everything in Unity Academy module is working as intended now except that DevTools warning, and if the answer to the question above is "changing module building system", maybe we can temporarily left everything just like this now, and if we figured out how to mark React as external for bundles, we can then upgrade our module building system in the future. |
I don't think there's a solution specific to unity academy, nor is there a solution that will work simply by changing the module build system without also modifying other parts like js-slang and the frontend. |
Steps to Reproduce
To investigate:
The text was updated successfully, but these errors were encountered: