controller method 'render component' fails to import properly where <%=react_component() %> successfully imports the same files)
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 32/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, rails, react
- Domain
- full-stack
Research direction
Start from the controller render component: entry point and compare its loading path with the view react_component method. Reproduce the failure using an import that references window.screen.availWidth or @uppy/react; done when controller rendering handles the same imports successfully as the view method.
Written by the indexing model from the issue text.
Description
Steps to reproduce
My intent was to have my application View Yield a react component that is defined in the controller via render component:... then i would rarely have to interact with rails Views, and react components are now my views.
This works in principle, but it fails under specific cases. Presumably because it renders the component in a different order to the render_component method available in Views as this method does not bug in the same way, and works as expected.
This will bug by giving an error:
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 your imports are fine, this was caused in my case by window.screen.availWidth used above the export default function Component(){}
being used in one of the imported files. This was in my case redundant so i could remove it for this import, but unfortunately i also import Uppy in one of my files and this causes the same error - import { DashboardModal } from '@uppy/react' (presumably because they do something similar, but i cannot change the source code here.)
This makes it impossible to render my react in this way. Which is annoying because i now have to use the view and it's more convoluted that way. The method react_component used in views works just fine and does not experience this bug - presumably because at compile time or similar the window object exists as opposed to rendered from the controller where the window has not been instanced, but thats a guess.
So to summarise - Controller method 'render component: ' fails to import certain files due to import error when View method react_component succeeds just fine. Presumably because they load the files at different times.
What should happen - the controller method should load the files at the same time as render_component in order to more robustly load imports. ( or if this is not the cause, the controller method should be brought in line with the view method so as not to fail imports )
Current workaround - just use Views with <%= react_component "Component" %> inside the view instead.
react rails 2.6.1
- Dominant language
- JavaScript
- Stars
- 6.8k
- Forks
- 739
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reactjs/react-rails
-
Documentation
Difficulty 4/5 3-5 days Newbie friendliness 45/100
reactjs/react-rails#1380 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
reactjs/react-rails#1355 · 1 comment · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
reactjs/react-rails#1351 · 4 comments · 10 reactions ·
-
discussion
Difficulty 4/5 3-5 days Newbie friendliness 35/100
reactjs/react-rails#1341 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
reactjs/react-rails#1338 · 3 comments ·
All issues in reactjs/react-rails
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
avniproject/avni-client#2135 ·
-
automated broken-link
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
agent/security hive/hosted-available-lke648397-260827-5n31 security
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
babalae/bettergi-scripts-list#3674 ·
-
A-Release-Notes C-Editing D-Modest S-Ready-For-Implementation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bevyengine/bevy-website#2595 ·