-
Notifications
You must be signed in to change notification settings - Fork 648
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
Use inheritance when prepending - Fixes conflict with other render gems #574
Conversation
Very cool. This has been an open issue for awhile with remotipart, turbolinks, and possibly others My desired approach in the future would be to eliminate hooking into I'll take a closer look soon. Do you think this should increment the MAJOR or MINOR value if conforming to Semver? Can you forsee be any backwards compatibility concerns with this? I do see you are checking Thanks a ton for giving this a proper look! |
No problem! Thanks for the prompt response :) I think this is a PATCH level change...as far as I can tell I haven't changed any functionality. The only thing I can think of that could break backwards compatibility is Personally I like the Renderers.add approach the most (that feature appears to exist as early as rails 3). It would let you call |
I've been sitting on this excellent work for too long. Thanks a ton for the help. |
Prepend is available since ruby 2, which is < 2.2, and thus always available. The previous solution, while unbreaking some cases (mileszs#574), still breaks others like ViewComponent with rails < 6.1 (ViewComponent/view_component#288). Because there is no longer any need to support old versions of ruby, we can dispense with the alias method chain, and thus use a pure prepend solution, which fixes the problem in these known cases. We preserve the `render_with_wicked_pdf` method for backwards compatibility.
Prepend is available since ruby 2, which is < 2.2, and thus always available. The previous solution, while unbreaking some cases (mileszs#574), still breaks others like ViewComponent with rails < 6.1 (ViewComponent/view_component#288). Because there is no longer any need to support old versions of ruby, we can dispense with the alias method chain, and thus use a pure prepend solution, which fixes the problem in these known cases. We preserve the `render_with_wicked_pdf` method for backwards compatibility.
Fixes are added to master branch. |
After upgrading to rails 5 we found that the way wicked_pdf prepends
ActionController::Base#render
causes an infinite loop when combined with another gem prepending render.I believe our issue is generally related to #111, though this PR focuses on prepend behavior.
The loop happens because wicked_pdf is not using the traditional prepend inheritance pattern, which looks like this
Instead, PdfHelper aliases the current render method away, then defines its own render method on the base class, which then calls the new render_with_wicked_pdf method.
If any other gem prepends its own render method using the inheritance pattern, before wicked_pdf prepends PdfHelper, this happens:
I've included a test that demonstrates this behavior. Its quite ugly as it has to replicate what railtie.rb does after another gem is prepended, which i couldn't figure out how to do since all of wicked is loaded before the tests run, so my solution was to just demonstrate it with a mock ActionController::Base class.
I'm new to test-unit so please let me know if these tests can be cleaned up.