hyperstack-org / hyperstack-org/hyperstack

es6 modules are assumed to have a default component

オープン
#231 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug good first issue
主要言語
JavaScript
スター
538
フォーク
41
PR マージ指標
30日以内にマージされた PR はありません

説明

related to #185

ES6 modules may not always have a default component. For example `Material-UI`.

The problem is the `eval_native_react_component` method assumes if its an es6 module, then there must be a default. This causes that method to attempt to evaluate properties of `undefined`.

The fix is to check if its an es6 module AND does it have a default:

```ruby
module Hyperstack
module Internal
module Component
class ReactWrapper
...
def self.eval_native_react_component(name)
component = `eval(name)`
raise "#{name} is not defined" if `#{component} === undefined`
# ------------> the following && component.default needs to be added <-------------
component = `component.default` if `component.__esModule && component.default`
is_component_class = `#{component}.prototype !== undefined` &&
(`!!#{component}.prototype.isReactComponent` ||
`!!#{component}.prototype.render`)
has_render_method = `typeof #{component}.render === "function"`
unless is_component_class || stateless?(component) || has_render_method
raise 'does not appear to be a native react component'
end
component
end
end
end
end
end
```

As a work around you can do this in your pack files:
```javascript
Mui = require('@material-ui/core');
Mui.default = Mui // <--- add this line ----
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。