-
Notifications
You must be signed in to change notification settings - Fork 645
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
Handle PdfHelper include vs prepend with separate modules #818
base: master
Are you sure you want to change the base?
Conversation
8a6fb2c
to
2bd7645
Compare
A little duplication for now is preferred to provide clarify and untangle the overriding paths.
Simplified a few times. Offering this PR as a way to fix #810. Build will pass, just needs a kick again. |
@adzap I've restarted those, and they have indeed passed, but I pulled this change into an older project I've managed to reproduce the issue in, and it still gets into an infinite loop on render. For reference: |
@unixmonkey thanks for testing. I don't use remotipart but had an infinite loop issue, which this PR solves. Seems the remotipart gem causes a variation this PR doesn't fix. I look into remotipart. |
@adzap Yep. Just adding it to your Gemfile should be enough to get an insta-crash, I think. |
@unixmonkey I can see remotipart is trying to avoid different override techniques and just stick with aliasing. The causes a conflict if wicked_pdf uses prepend and remotipart is aliasing our Would be great if remotipart supported prepend, but until then we need to work around it. Options I see:
|
@adzap That's great! I didn't realize you could order initializers like that. initializer 'wicked_pdf.register', :after => 'remotipart.controller_helper' do |_app|
# include/prepend stuff
end Do you see any issues with that approach? |
It would good to add it as config and make it empty. Then instruct people to add it the initialiser names as required eg the remotipart one.
That way we support any issue like this without a problem.
Don’t like idea of adding code specific to some other random unrelated gem.
…On 26 Mar 2019, 11:10 AM +1100, David Jones ***@***.***>, wrote:
@adzap That's great! I didn't realize you could order initializers like that.
This seems to solve the immediate problem, and doesn't seem to have any negative effects when that gem/initializer isn't in the project. I'm inclined to release a version with just that addition like so:
initializer 'wicked_pdf.register', :after => 'remotipart.controller_helper' do |_app|
# include/prepend stuff
end
Do you see any issues with that approach?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I don’t see a good way to do that since the railtie is loaded before the wicked_pdf.rb initializer. |
You're right, I hadn't thought of that. Then option 3 seems like the way forward. I don't like this idea of putting in work arounds for some other badly behaving gem. |
Can you tell me if just moving the remotipart gem declaration in your Gemfile above wicked_pdf fixes this?
…On 26 Mar 2019, 12:27 PM +1100, David Jones ***@***.***>, wrote:
I don’t see a good way to do that since the railtie is loaded before the wicked_pdf.rb initializer.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
No, changing the position in the Gemfile appears to have no effect. I put remotipart at the top, and wicked_pdf at the bottom with no change in behavior. Option 3 also doesn't work for me in this app, but it seems to be because Regarding passing configuration to the railtie, we can do that if it's defined in module MyApp
class Application < Rails::Application
config.wicked_pdf.skip_render_overrides = true
config.wicked_pdf.skip_asset_helpers = true if the railtie is something like this: class WickedRailtie < Rails::Railtie
config.wicked_pdf = ActiveSupport::OrderedOptions.new
initializer 'wicked_pdf.register' do |app|
unless app.config.wicked_pdf.skip_render_overrides
# includes/prepends
end
unless app.config.wicked_pdf.skip_asset_helpers
# asset include
end Then manually include Allowing you to opt-in or out of magic stuff in the railtie is on my radar anyway, but I'm not sold on the naming, since you could |
I think I would probably invert the naming logic to something like Also rather than creating parallel gem config, I would do this
I think the future should be that we don't need a PdfHelper at all. With my suggested extraction of the controller render helper methods into a Renderer object and defining a |
To add this config and extra complexity now seems more problematic than just moving to the Renderer solution which solves the render method problem as Rails intended and we can leave the render_to_string override in place because it is far less contentious a method.
I can fix up the existing PR and remove some of the unnecessary commits. Let me know if you’re up for it.
…On 27 Mar 2019, 3:18 AM +1100, David Jones ***@***.***>, wrote:
No, changing the position in the Gemfile appears to have no effect. I put remotipart at the top, and wicked_pdf at the bottom with no change in behavior.
Option 3 also doesn't work for me in this app, but it seems to be because config/initializers/wicked_pdf.rb is evaluated before config.after_initialize, and since it isn't required, the constant doesn't exist yet.
Regarding passing configuration to the railtie, we can do that if it's defined in config/application.rb like this:
module MyApp
class Application < Rails::Application
config.wicked_pdf.skip_render_overrides = true
config.wicked_pdf.skip_asset_helpers = true
if the railtie is something like this:
class WickedRailtie < Rails::Railtie
config.wicked_pdf = ActiveSupport::OrderedOptions.new
initializer 'wicked_pdf.register' do |app|
unless app.config.wicked_pdf.skip_render_overrides
# includes/prepends
end
unless app.config.wicked_pdf.skip_asset_helpers
# asset include
end
Then manually include WickedPdf::PdfHelper in ApplicationController (or a specific controller).
Allowing you to opt-in or out of magic stuff in the railtie is on my radar anyway, but I'm not sold on the naming, since you could skip_render_overrides = true, but if you include it in your controller, you are still overriding, just later in the process.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I agree with the sentiment, but I think it's important to go through a deprecation cycle and throw warnings for stuff we are going to remove. This is a very widely used library, and it's already very tricky to upgrade I'd rather throw a temporary hack in to make this a safe upgrade for 1.x users, with a path to use a new renderer in preparation for a 2.x, because I guarantee people are out there using parts of the API we would be removing. |
Ok I understand. The render method is the public API so a change to that would be a semver-like break. You have the experience with the user community so I defer to you on that. Unfortunately these config changes won't be a fix for me as my wicked_pdf usage is from another gem which I'm not inclined to change it to add this fix as it requires config change and changes to controller code. So I'll probably have to release my own fork gem. Unless you have a suggested path to a v2 alpha/beta release I can assist with in the short term? |
I have the same issue when using it together with |
WickedPDF may be causing the 'fatal (machine stack overflow in critical region)' error that we're receiving. See mileszs/wicked_pdf#818
As a solution to the current infinite loop issue, I've approached it by handling include vs prepend slightly differently so that you are just using
alias_method_chain
orsuper
respectively. No getting these jumbled by using a single module to handle both cases.