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

RSpec example tests fail under mini_racer #1447

Closed
alexeyr-c opened this issue Apr 20, 2022 · 2 comments · Fixed by #1461
Closed

RSpec example tests fail under mini_racer #1447

alexeyr-c opened this issue Apr 20, 2022 · 2 comments · Fixed by #1461

Comments

@alexeyr-c
Copy link

A bug is a crash or incorrect behavior. If you have a debugging or troubleshooting question, please open a discussion.

Environment

  1. Ruby version: 3.0.2
  2. Rails version: 7.0.2.3
  3. Webpacker version: 6.2.1
  4. React on Rails version: 13.0.2

Expected behavior

Running bundle exec rspec:examples should work.

Actual behavior

It fails with

Failures:

  1) Hello World the hello world example works
     Failure/Error: <%= react_component("HelloWorld", props: @hello_world_props, prerender: true) %>

     ActionView::Template::Error:
       ERROR in SERVER PRERENDERING
       Encountered error:

       Error evaluating server bundle. Check your webpack configuration.
       ===============================================================
       Caught error:
       ReferenceError: TextEncoder is not defined
       ===============================================================


       when prerendering HelloWorld with props: {"name":"Stranger"}

       code:

               (function() {
                 var railsContext = {"railsEnv":"test","inMailer":false,"i18nLocale":"en","i18nDefaultLocale":"en","rorVersion":"13.0.2","rorPro":false,"href":"http://127.0.0.1:41625/hello_world","location":"/hello_world","scheme":"http","host":"127.0.0.1","port":41625,"pathname":"/hello_world","search":null,"httpAcceptLanguage":"en-US","serverSide":true};
                     ReactOnRails.clearHydratedStores();

                 var props = {"name":"Stranger"};
                 return ReactOnRails.serverRenderReactComponent({
                   name: 'HelloWorld',
                   domNodeId: 'HelloWorld-react-component-c7c7e733-908a-45dd-ba94-3d705b873234',
                   props: props,
                   trace: false,
                   railsContext: railsContext
                 });
               })()



       eval (webpack://app/./node_modules/react-dom/cjs/react-dom-server.browser.development.js?:145:19)
       eval (webpack://app/./node_modules/react-dom/cjs/react-dom-server.browser.development.js?:6712:5)
       Object.866 ((execjs):114:1)
       __webpack_require__ ((execjs):346:42)
       eval (webpack://app/./node_modules/react-dom/server.browser.js?:6:7)
       Object.762 ((execjs):138:1)
       __webpack_require__ ((execjs):346:42)
       eval (webpack://app/./node_modules/react-on-rails/node_package/lib/handleError.js?:7:32)
       Object.695 ((execjs):234:1)
       __webpack_require__ ((execjs):346:42)
       /home/runner/work/react_on_rails/react_on_rails/vendor/bundle/ruby/2.7.0/gems/mini_racer-0.6.2/lib/mini_racer.rb:223:in `eval_unsafe'
       /home/runner/work/react_on_rails/react_on_rails/vendor/bundle/ruby/2.7.0/gems/mini_racer-0.6.2/lib/mini_racer.rb:223:in `block (2 levels) in eval'
       /home/runner/work/react_on_rails/react_on_rails/vendor/bundle/ruby/2.7.0/gems/mini_racer-0.6.2/lib/mini_racer.rb:343:in `timeout'
       /home/runner/work/react_on_rails/react_on_rails/vendor/bundle/ruby/2.7.0/gems/mini_racer-0.6.2/lib/mini_racer.rb:222:in `block in eval'
       /home/runner/work/react_on_rails/react_on_rails/vendor/bundle/ruby/2.7.0/gems/mini_racer-0.6.2/lib/mini_racer.rb:220:in `synchronize'

     [Screenshot Image]: /home/runner/work/react_on_rails/react_on_rails/gen-examples/examples/basic-server-rendering/tmp/capybara/failures_r_spec_example_groups_hello_world_the_hello_world_example_works_635.png


     # /home/runner/work/react_on_rails/react_on_rails/lib/react_on_rails/helper.rb:488:in `rescue in server_rendered_react_component'
     # /home/runner/work/react_on_rails/react_on_rails/lib/react_on_rails/helper.rb:484:in `server_rendered_react_component'
     # /home/runner/work/react_on_rails/react_on_rails/lib/react_on_rails/helper.rb:426:in `internal_react_component'
     # /home/runner/work/react_on_rails/react_on_rails/lib/react_on_rails/helper.rb:57:in `react_component'
     # ./app/views/hello_world/index.html.erb:2:in `_app_views_hello_world_index_html_erb___460236627246907381_15280'
     # ------------------
     # --- Caused by: ---
     # MiniRacer::RuntimeError:
     #   ReferenceError: TextEncoder is not defined
     #   JavaScript at eval (webpack://app/./node_modules/react-dom/cjs/react-dom-server.browser.development.js?:145:19)

Finished in 24.33 seconds (files took 2.83 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/system/hello_world_spec.rb:6 # Hello World the hello world example works

rake aborted!
Command failed with status (1): [cd /home/runner/work/react_on_rails/react_...]
/home/runner/work/react_on_rails/react_on_rails/rakelib/task_helpers.rb:21:in `block in sh_in_dir'
/home/runner/work/react_on_rails/react_on_rails/rakelib/task_helpers.rb:21:in `each'
/home/runner/work/react_on_rails/react_on_rails/rakelib/task_helpers.rb:21:in `sh_in_dir'
/home/runner/work/react_on_rails/react_on_rails/rakelib/run_rspec.rake:111:in `run_tests_in'
/home/runner/work/react_on_rails/react_on_rails/rakelib/run_rspec.rake:41:in `block (3 levels) in <top (required)>'
/home/runner/work/react_on_rails/react_on_rails/rakelib/run_rspec.rake:47:in `block (3 levels) in <top (required)>'
/home/runner/work/react_on_rails/react_on_rails/rakelib/run_rspec.rake:47:in `each'
/home/runner/work/react_on_rails/react_on_rails/rakelib/run_rspec.rake:47:in `block (2 levels) in <top (required)>'
/home/runner/work/react_on_rails/react_on_rails/vendor/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/opt/hostedtoolcache/Ruby/2.7.6/x64/bin/bundle:23:in `load'
/opt/hostedtoolcache/Ruby/2.7.6/x64/bin/bundle:23:in `<main>'
Tasks: TOP => run_rspec:example_basic-server-rendering
(See full trace by running task with --trace)
Error: Process completed with exit code 1.

I tried to run it without mini_racer (rebasing over #1437), and examples succeed (at least locally).

The same failure happens on CI for trivial PRs, so #1437 will probably fix it. If we don't want to accept it or if we still want mini_racer compatibility for server rendering, this issue should be kept open and in the second case tests for mini_racer added.

@tomdracz
Copy link
Contributor

https://reactrails.slack.com/archives/C0HFLD6S0/p1652474744534739 seems to be the same thing

cc @justin808 should go away after we merge my PR 🤞

@justin808
Copy link
Member

Fixed!

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 a pull request may close this issue.

3 participants