Skip to content

Commit 31b1744

Browse files
committed
Conditionally define ViewComponent::Base#format for Rails 7.1 only
1 parent 004314c commit 31b1744

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/view_component/base.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,12 @@ def view_cache_dependencies
316316
[]
317317
end
318318

319-
# Rails expects us to define `format` on all renderables,
320-
# but we do not know the `format` of a ViewComponent until runtime.
321-
def format
322-
nil
319+
if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1
320+
# Rails expects us to define `format` on all renderables,
321+
# but we do not know the `format` of a ViewComponent until runtime.
322+
def format
323+
nil
324+
end
323325
end
324326

325327
# The current request. Use sparingly as doing so introduces coupling that

0 commit comments

Comments
 (0)