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

mountComponents gets called before registerComponents

Open biw opened this issue 6 years ago • 2 comments

Hi! I am currently trying to set up webpacker-react in a codebase and am having a little trouble. I have an application.js pack that has dynamically loaded imports. Inside the modules I load, I call WebpackerReact.setup({ reactElm }). I get the following function call sequence:

  1. setup()
  2. mountComponents
  3. registerComponents
  4. mountComponents

Which throws Error: webpacker-react: cant render a component that has not been registered: HubBlock. I understand is due to:

https://github.com/renchap/webpacker-react/blob/563cd74775c588cdf1048332ac1f10f9cac4a7fe/javascript/webpacker_react-npm-module/src/index.js#L83-L89

I can call registerComponents and mountComponents without calling setup fix this. Am I doing something wrong? Is calling them on their own without setup okay?

biw avatar Dec 01 '17 21:12 biw

Can you show me what your application.js looks like (the Webpacker calls as well as the imports and the general structure)?

renchap avatar Dec 01 '17 22:12 renchap

import 'babel-polyfill'

const pages = {
  show: async () => {
    await import(/* webpackChunkName: 'show' */ 'show')
  },
}

const { name } = window.page

// load the show page
pages[name]()

and show/index.js looks like:

import WebpackerReact from 'webpacker-react'
import reactBlock from './reactBlock'

// WebpackerReact.setup({ reactBlock })
WebpackerReact.registerComponents({ reactBlock })
WebpackerReact.mountComponents({ reactBlock })

biw avatar Dec 01 '17 23:12 biw