react-rails icon indicating copy to clipboard operation
react-rails copied to clipboard

Unable to SSR components

Open EnriqueVidal opened this issue 6 years ago • 2 comments

Help us help you! Have you looked for similar issues? Do you have reproduction steps? Contributing Guide

Steps to reproduce

(Guidelines for creating a bug report are available here)

Expected behavior

Should SSR components that it's already able to CSR

Actual behavior

Apparently it can't import my component for server rendering

System configuration

  • ruby 2.4.5
  • rails 4.2.11
  • react-rails 2.6.0
  • webpacker 3.6.0 - can move back to 4.x just rolled back to see if this could be an issue with webpacker

Hi I am working on a legacy Rails 4 application that was using sprockets for components and just recently had to use babel and npm modules, I added webpacker (4.x and also tried 3.6) and kept old components in sprockets (which still work) and new components written in ES6 using modules in webpacker (only client side rendering works).

I have not been able to pre-render my components even though the client render alright, also I see the compiled version under public/packs/js, my component lives under app/javascripts/components and am adding the application pack.

I've tried also include server_redering but every example I see just includes application, I also tried including my componen as a pack, but been unsuccessful, it baffles me that client rendering works though and with little to go on I turn to the community for help, this is the error I get when I try to server render:

#<ExecJS::ProgramError: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.>" when prerendering NavBar with {}

I am most definitely default exporting that component and as mentioned before the moment I drop prerender: true it renders but given this component has many links I need it to server render.

I installed as:

rake webpacker:install
rake webpacker:install:react
rails g react:install

sprockets component still work in conjuction with client side rendering, and I'd like to keep it that way for now since we got about 65 legacy components that I rather not touch at this moment.

Thanks in advance.

EnriqueVidal avatar Sep 27 '19 16:09 EnriqueVidal

Ever sort this out @EnriqueVidal ? I’ve come across this but it’s very sporadic.

bryanberger avatar Mar 03 '20 00:03 bryanberger

@bryanberger We dropped completely because we had to get something out, I wish I had more time to work on this but unfortunately we needed to move on.

EnriqueVidal avatar Mar 03 '20 16:03 EnriqueVidal

@EnriqueVidal @bryanberger, as per the above discussion closing the issue for now. Feel free to reopen it, if it's reproducible.

alkesh26 avatar Nov 07 '22 09:11 alkesh26