opal / opal-sprockets

Sprockets support for Opal (used to be embedded into Opal from v0.6 up to v0.10)
29 stars 17 forks source link

Fix issue with upgrading gems breaking Opal compilation in Rails applications due to incorrect Sprockets caching #34

Closed AndyObtiva closed 3 months ago

AndyObtiva commented 4 months ago

Fix issue with upgrading gems breaking Opal compilation in Rails applications due to incorrect Sprockets caching (more details are included below).

In the past, I was forced to run rm -rf tmp/catche after every upgrade of gems that were using Opal.

Now, with this fix, the problem goes away without having to do that anymore.

This was an issue mentioned in Opal Slack as:

I ran into a generally consistent issue when using Opal in a Rails app. If I update my Rails app gem dependencies (like the glimmer-dsl-web gem that depends on Opal or some other gems) and I restart the server, when I access the webpage that uses Opal, it gives me weird errors (they are untraceable to my code). I discovered that the consistent fix for the issue is to always run rm -rf tmp/cache after updating any gems in the Rails app, and then to restart the server afterwards. I don't run into the issue anymore if I do run rm -rf tmp/cache after updating any gems. Of course, the downside to this is I lose caching, so the next request takes a little longer than normal. Also, it requires a manual step from me after updating any gems. This seems to be caused by the way Opal caches data in the Rails server. It must have a bug that breaks it if the Ruby gems change (like changing versions or perhaps changing gem paths given that gems have the version number in their path name). I just wanted to note it in case you are not aware of this issue so that you would fix it.