Skip to content

Fix react_component bug#950

Closed
Judahmeek wants to merge 3 commits intomasterfrom
jmeek/hash_results
Closed

Fix react_component bug#950
Judahmeek wants to merge 3 commits intomasterfrom
jmeek/hash_results

Conversation

@Judahmeek
Copy link
Copy Markdown
Contributor

@Judahmeek Judahmeek commented Oct 3, 2017

Expected behavior: If the user signals ReactOnRails that the user expects react_component to return a Hash (which is currently done through https://github.com/shakacode/react_on_rails/pull/800/files#diff-04c6e90faac2675aa89e2176d2eec7d8R343), then react_component should return a Hash or nil in all cases.

Actual behavior: The current signal for react_component to return a Hash requires successful rendering. Any error in the react code will result in the signal being lost and react_component returning a string.


This change is Reviewable

@Judahmeek Judahmeek requested a review from udovenko October 3, 2017 09:52
@Judahmeek Judahmeek changed the title Fix react_component bug Fix react_component bug Oct 3, 2017
@Judahmeek
Copy link
Copy Markdown
Contributor Author

Tests only fail because of the the same issue failing all recent react_on_rails tests: something in the HelloWorldApp used by the Basic Example. I think it's likely https://github.com/shakacode/react_on_rails/blob/master/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb#L10, but I have yet to confirm this.

@udovenko
Copy link
Copy Markdown
Contributor

udovenko commented Oct 4, 2017

Generally LGTM, just few comments...


Review status: 0 of 11 files reviewed at latest revision, 2 unresolved discussions, some commit checks broke.


spec/dummy/app/views/pages/broken_app.html.erb, line 1 at r1 (raw file):

<%= render "header" %>

broken_app name seems too abstract here (while BrokenApp component name is ok). I would express that we're demonstrating hash result behavour in template name.


spec/dummy/spec/features/integration_spec.rb, line 200 at r1 (raw file):

  scenario "react_component should return hash" do
    expect(subject.html).to include("Exception in rendering!")
  end

Should we also add a "black" test for case when we retruning a hash but hash_result == false?


Comments from Reviewable

@udovenko
Copy link
Copy Markdown
Contributor

udovenko commented Oct 4, 2017

Reviewed 11 of 11 files at r1.
Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks broke.


Comments from Reviewable

@justin808
Copy link
Copy Markdown
Member

  1. I'm not clear on why we need a new option on the error handling. @robwise has commented that we give too many options on this.
  2. If we were to add an option, the PR needs docs...

I'd like to see "it just works" behavior. Is there possibly a super clear choice as to which is behavior is the only one we need?


Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks broke.


Comments from Reviewable

@justin808
Copy link
Copy Markdown
Member

Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks broke.


spec/dummy/app/views/pages/broken_app.html.erb, line 1 at r1 (raw file):

Previously, udovenko (Denis Udovenko) wrote…

broken_app name seems too abstract here (while BrokenApp component name is ok). I would express that we're demonstrating hash result behavour in template name.

I agree with @udovenko.


spec/dummy/spec/features/integration_spec.rb, line 200 at r1 (raw file):

Previously, udovenko (Denis Udovenko) wrote…

Should we also add a "black" test for case when we retruning a hash but hash_result == false?

I agree with @udovenko. But we first need to decide why we need both cases...Maybe a little doc would clarify?


Comments from Reviewable

server_rendered_html = result["html"]

if result["hasErrors"] && options.hash_result
server_rendered_html = Hash[COMPONENT_HTML_KEY, result["html"]]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

prefer normal hash literal syntax:

server_rendered_html = { COMPONENT_HTML_KEY => result["html"] }

end

def hash_result
retrieve_key(:hash_result)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please update the retrieve_key implementation as follows:

  def retrieve_key(key)
    options.fetch(key) do
      if ReactOnRails.configuration.methods.include?(key)
        ReactOnRails.configuration.public_send(key)
      else
        nil
      end
    end
  end

This will allow you to remove the hash_key option from the initializer configuration and keep it as only an option you can pass to react_component directly. Previously, the assumption had been made that every option passed to react_component had a fallback default in the initializer, but in this scenario, that would make no sense and it's unnecessarily expanding the public API of the initializer.

replay_console: true,
logging_on_server: true,
raise_on_prerender_error: false,
hash_result: false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See comment for react_component/options.rb, we should remove all of this

@Judahmeek
Copy link
Copy Markdown
Contributor Author

It was decided that a documentation PR would address the concerns of this PR without the need to add yet another option parameter to react_component.

@Judahmeek Judahmeek closed this Oct 5, 2017
@Judahmeek Judahmeek deleted the jmeek/hash_results branch October 5, 2017 03:59
justin808 pushed a commit that referenced this pull request Oct 24, 2017
When I created #951, I forgot to add the useful functionality from #950 that would ensure that react_component_hash worked correctly. When there is a prerendering error, react_component_hash should return the result combined with the console logs as a hash even though every prerendering error is returned from Exec as a String. Right now, if a prerendering error occurs, react_component_hash throws its "Expected a Hash" error
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.

4 participants