-
Notifications
You must be signed in to change notification settings - Fork 443
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
coexistence with wicked_pdf #288
Comments
@ocarreterom thank you for the report! This was also being discussed here: #257 Do you have a proposed solution in mind? Unfortunately the conflict is due to competing monkey patches of I could see having an option to turn off the ViewComponent monkey patch, potentially allowing some sort of alternate render method such as |
This monkey patch is due to the backport and it might will be fixed in Rails 6.1? |
@ocarreterom correct. If you're running |
@joelhawksley Providing a view helper like I do wonder if we implemented the monkey patch like wicker_pdf could they coexist: https://github.com/mileszs/wicked_pdf/blob/08a104c2115147410b8008079cba08c5d8a5f226/lib/wicked_pdf/pdf_helper.rb#L37 There is explicit support there for alias_chaining there. We could try that pattern. If it worked we'd have zero config compatibility. While Rails 6.1 isn't going to have this problem I wonder if we should make the effort to build it "the right way" for older Rails versions. |
@jonspalmer oh, interesting. It would certainly be worth a shot! @ocarreterom would you be interested in giving that approach a try? Our CI builds against Rails 5, 6, and master in a matrix, so we should be able to be fairly confident in test feedback here. |
@ocarreterom I have a spike of this approach going...stay tuned. |
Actually scratch that. As I dig into the wicked_pdf code it's functionally equivalent to the code we have already given we're prepending the monkey patch. For some reason wicked_pdf is also trying to handle the included case as well as prepend. I don't think we care about that. So I think we're back to our original idea. That said I'd love to know why this breaks in the first place. Is it view_component doing something unexpected or is it wicked_pdf? |
One hacky workaround is to use the class WickedPdf
module PdfHelper
remove_method(:render)
end
end Obviously not the most desirable workaround haha, but it will allow the two to exist together until a more legitimate solution exists (I've been experimenting with this in my rails 5.2 environment where it is currently functioning) |
@jonspalmer Incase
This then causes an infinity loop. Incase only
|
I created the following draft PR: #358 |
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.
I believe wicked_pdf is doing magic it doesn't need, so I posted mileszs/wicked_pdf#925 removing it, replacing with a patch very similar to view_component |
#358 got merged. In order to make wicked_pdf compatible with view_component please set the config option |
Currently I have stopped using wicked_pdf. Thank for your dedication! ❤️ |
I consider this issue resolved. Thanks for your hard work and dedication @johannesengl! |
For the record, I'm currently using (not in production yet, migration to ViewComponent is in progress) the following WickedPdf monkey patch to avoid having to use class WickedPdf
# Wicked Pdf magic breaks ViewComponent
# https://github.com/mileszs/wicked_pdf/pull/925
module PdfHelper
def render(*args)
options = args.first
if options.is_a?(Hash) && options.key?(:pdf)
render_with_wicked_pdf(options)
else
super
end
end
def render_to_string(*args)
options = args.first
if options.is_a?(Hash) && options.key?(:pdf)
render_to_string_with_wicked_pdf(options)
else
super
end
end
end
end |
Steps to reproduce
Add
wicked_pdf
to your Gemfile.Expected behavior
Work well.
Actual behavior
I get an error:
System configuration
Rails version: 6.0.2.2
Ruby version: 2.6.5
Gem version: 2.2.1
The text was updated successfully, but these errors were encountered: