Skip to content

2nd render of props partial returns nil #63

Closed

Description

@aseroff

Background: I have partials for objects that provide their data for JSON APIs, as well as JSON+LD metadata for HTML views. In my backend, there's a place to view that metadata. The code looks like this:

#jsonld.tab-pane{role: 'tabpanel'}
  %h3 JSON-LD Metadata:
  %small This is used to provide rich Google search results to our library pages.
  .card.bg-body-tertiary
    %code.card-body
      %pre= JSON.pretty_generate ActiveSupport::JSON.decode(render(partial: 'library/jsonld/book', formats: [:json], locals: {book: @book}))
#jsonapi.tab-pane{role: 'tabpanel'}
  %h3 Public API JSON repsonse:
  .card.bg-body-tertiary
    %code.card-body
      %pre= JSON.pretty_generate ActiveSupport::JSON.decode(render(partial: 'library/books/book', formats: [:json], locals: {book: @book}))

This code raised an error, that the second instance of ActiveSupport::JSON.decode can't be passed nil. But strangely, if I comment out the first partial render, the second one works just fine. Flip them, and nil is still rendered for the 2nd partial. It seems like there's some sort of behind the scenes issue going on here with rendering multiple .props partials in the same view, and I just wanted to pass it on. (This code worked just fine using jbuilder templates)

Activity

  1. jho406 commented on Mar 1, 2026

    @jho406
    Contributor

    I honestly did not expect this use case, but its something we should support. I'll take a look at this, and thank you for reporting it!

  2. added a commit that references this issue on Mar 3, 2026
    d00e2c4
  3. jho406 commented on Mar 3, 2026

    @jho406
    Contributor

    @aseroff try out this branch and see if it works out for you: #64

  4. aseroff commented on Mar 3, 2026

    @aseroff
    Author

    @aseroff try out this branch and see if it works out for you: #64

    This branch does solve the issue. Thanks for taking a look and addressing the issue!

  5. jho406 commented on Mar 4, 2026

    @jho406
    Contributor

    nice! I'll stress test it on my end and release a minor this weekend. Thanks!

  6. jho406 commented on Mar 7, 2026

    @jho406
    Contributor

    v1.0.1 released.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions