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

OptimizedFileSystemResolver doesn't sort views considering request format #37556

Closed
iagopiimenta opened this issue Oct 24, 2019 · 4 comments
Closed

Comments

@iagopiimenta
Copy link
Contributor

iagopiimenta commented Oct 24, 2019

Steps to reproduce

  1. Create a new rails 6 project: rails new bug
  2. Generate a controller for users#index: rails generate controller users index
  3. Add a json view for index: echo "json.foo 'bar'" > app/views/users/index.json.jbuilder
  4. Run development server: rails s
  5. Make a request for users with accepting json format:
  curl 'http://localhost:3000/users' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'X-Requested-With: XMLHttpRequest'
  1. Confirm that response have the html content instead of json content.

Expected behavior

The request should prioritize the format passed by Accept: application/json, text/javascript, */*; q=0.01 header and render the index.json.jbuilder view.

Actual behavior

The index.html.erb view is rendered.

System configuration

Rails version:
6.0.0

Ruby version:
2.5.5

Additional Information

With rails 5.2.3 it works perfectly. But rails 6 uses faster globs for template resolving which sorts files without prioritizing format.

@iagopiimenta iagopiimenta changed the title 6.0.0 - OptimizedFileSystemResolver doesn't sort views considering request formats 6.0.0 - OptimizedFileSystemResolver doesn't sort views considering request format Oct 24, 2019
@iagopiimenta iagopiimenta changed the title 6.0.0 - OptimizedFileSystemResolver doesn't sort views considering request format OptimizedFileSystemResolver doesn't sort views considering request format Nov 15, 2019
@jhawthorn
Copy link
Member

Fixed by #37557

@aardvarkk
Copy link

I'm not entirely clear on how Rails releases work, and also not sure exactly where to write this! Apologies if it's not the place. This issue is preventing me from upgrading to Rails 6. I noticed it's in the master branch, but it's been there for quite a while and wasn't included in the latest patch release(s). When might I expect this bug to get fixed in a release so I can continue the upgrade to Rails 6? Would this be present in 6.1, but not any of the patch releases on 6.0 before then?

@jonathanhefner
Copy link
Member

@aardvarkk Major and minor releases are cut from master branch, while patch releases are cut from a stable branch (6-0-stable in this case). So this will definitely be in Rails 6.1.

This fix hasn't yet been backported from master to 6-0-stable, which is why it wasn't included in Rails 6.0.3. (Backports are done on a case-by-case basis usually depending on the severity of the bug / necessity of the fix.)

For now, as a workaround, I've found that adding a respond_to block in the controller action can fix the issue:

respond_to do |format|
  format.html { }
  format.json { }
end

@aardvarkk
Copy link

@jonathanhefner Thanks very much for your detailed response. I had determined that a workaround was possible, but I'm working with a fairly large legacy codebase and was trying to avoid a large diff for the Rails 6 upgrade. We're not in a huge rush to upgrade so I guess the best option is likely to wait for the 6.1 release. Thanks again!

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

Successfully merging a pull request may close this issue.

5 participants