Skip to content
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

Add configuration to compatibility doc #1095

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

dpaola2
Copy link
Contributor

@dpaola2 dpaola2 commented Oct 12, 2021

Summary

For some reason, my Rails 5.0.7.2 app had nil as the view_component_path. Why? I have no idea. This resolved the issue for me. I am not sure if it's appropriate but I figured it couldn't hurt to add it to the compatibility doc.

For some reason, my Rails 5.0.7.2 app had `nil` as the `view_component_path`. Why? I have no idea. This resolved the issue for me. I am not sure if it's appropriate but I figured it couldn't hurt to add it to the compatibility doc.
@dpaola2 dpaola2 requested a review from as a code owner Oct 12, 2021
@joelhawksley
Copy link
Contributor

@joelhawksley joelhawksley commented Oct 13, 2021

@dpaola2 thanks for filing. Might you be up for trying to get a failing build that this change fixes? I'd hate for us to accidentally break this fix in the future.

@dpaola2
Copy link
Contributor Author

@dpaola2 dpaola2 commented Oct 14, 2021

@joelhawksley Here you go. Just adding the rails version replicated the issue, with the same unhandled exception I saw in my app. I spent a bit of time trying to figure out why this might be but it wasn't obvious at first glance.

@rmacklin
Copy link
Collaborator

@rmacklin rmacklin commented Oct 14, 2021

It stems from this:

mattr_accessor :view_component_path, instance_writer: false, default: "app/components"

Support for the default parameter of mattr_accessor was introduced in this PR which was first introduced in Rails 5.2

image

So, the same issue would affect Rails 5.1 apps as well. It's worth noting that only Rails 5.2 (and not earlier 5.x versions) is still officially supported by Rails (in that it still receives security patches), but even Rails 5.2 support will be dropped when Rails 7 is released. That said, it's possible to address this issue without committing ViewComponent to officially support Rails 5.0/5.1 (but note that there are additional mattr_accessor calls that use the default parameter; so this wouldn't only affect view_component_path).

@dpaola2
Copy link
Contributor Author

@dpaola2 dpaola2 commented Oct 15, 2021

Makes sense. FWIW the official docs (in docs/compatibility.md) indicate support for Rails 5.0+. Not making a statement of whether y'all should support it. Your logic makes sense to me!

.github/workflows/ci.yml Outdated Show resolved Hide resolved
docs/CHANGELOG.md Show resolved Hide resolved
@joelhawksley
Copy link
Contributor

@joelhawksley joelhawksley commented Oct 21, 2021

@dpaola2 it looks like this build is still failing due to other incompatibilities with Rails 5. Would you be up for fixing them? I assume you're looking to use VC with Rails 5.0 and would be happy to accept any (reasonable) patches to make that possible.

@dpaola2 dpaola2 requested a review from juanmanuelramallo as a code owner Feb 11, 2022
@dpaola2 dpaola2 requested a review from elia as a code owner Feb 11, 2022
@Spone
Copy link
Collaborator

@Spone Spone commented Feb 11, 2022

👋 @dpaola2 I took some time to get the tests to pass on Rails 5.0.

I took the easy path and skipped some tests:

  • all tests in relation to Translatable are skipped: the translate method signature changed with Rails 5.2, so I guess we should mention that this module is not supported in Rails < 5.2
  • test_uses_default_form_builder relies on helpers.fields that has been introduced in Rails 5.1

Also:

  • Prism syntax highlighting for previews is disabled in Rails < 5.2 (problems with asset_path)
  • I refactored EditorbComponent so it doesn't rely on translations (it's unrelated to the purpose of the test)

So I'd like to request the opinion of the maintainers on this: should we spend a bit more time on this and merge it, or just change the docs to mention compatibility with Rails 5.2+ only?

Copy link
Contributor

@camertron camertron left a comment

Just a few questions 😄

docs/CHANGELOG.md Show resolved Hide resolved
# config.view_component.render_monkey_patch_enabled = false
#
mattr_accessor :render_monkey_patch_enabled, instance_writer: false, default: true
if Rails.version.to_f >= 5.2
Copy link
Contributor

@camertron camertron Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think passing a block is supported in all the Rails versions we want to support, so what if we always pass a block here and avoid the Rails version check?

Copy link
Collaborator

@Spone Spone Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, but the newer syntax is with the default: keyword argument, that's why I went with it.

Either way is fine with me.

Copy link
Contributor

@camertron camertron Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nice thing about the block approach is that it's only called if no value has been provided, meaning it could potentially cut down on unnecessary object allocations. I can't imagine it'd save that many, but still worth considering.

test/view_component/integration_test.rb Show resolved Hide resolved
@@ -3,85 +3,87 @@
require "test_helper"

class TranslatableTest < ViewComponent::TestCase
def test_isolated_translations
render_inline(TranslatableComponent.new)
if Rails.version.to_f >= 5.2
Copy link
Contributor

@camertron camertron Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm so all these tests only work if the Rails version is 5.2 or later? Why is that?

Copy link
Collaborator

@Spone Spone Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is more work needed to make Translatable work with Rails < 5.2. I wanted to know if y'all think it's worth it to spend more time trying to support older Rails before tackling this.

Copy link
Contributor

@camertron camertron Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should support up to 5.2 since that's the oldest currently supported version. If adding support for < 5.2 were easy, I'd say let's go for it. Since it's more difficult, I'm inclined to say no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants