Hotkeys component results in TypeError with ES6 target #2972
Closed
Description
N.B. this is a more actionable version of #2535 with repro links.
Environment
- Package version(s): 3.6.1
- Browser and OS versions: MacOS Chrome 68
Steps to reproduce
- Use
target: es6
intsconfig.json
. - Add a
@HotkeysTarget
and associated code as the docs describe.
Rationale
Per @giladgray
targeting es5 is a good practice for browser apps as es6+ is inconsistently supported.
In general, this makes sense to me. However, I would consider apps primarily intended for personal/internal use where modern browsers are implied as an exception (or Electron apps). Forwards compatibility also seems like a good way to 'future proof'.
Actual behavior
See https://codesandbox.io/s/7yp63vw621:
TypeError: Class constructor App cannot be invoked without 'new'
at new HotkeysTargetClass (https://7yp63vw621.codesandbox.io/node_modules/@blueprintjs/core/lib/cjs/components/hotkeys/hotkeysTarget.js:20:50)
at constructClassInstance (https://7yp63vw621.codesandbox.io/node_modules/react-dom/cjs/react-dom.development.js:6789:20)
at updateClassComponent (https://7yp63vw621.codesandbox.io/node_modules/react-dom/cjs/react-dom.development.js:8324:9)
at beginWork (https://7yp63vw621.codesandbox.io/node_modules/react-dom/cjs/react-dom.development.js:8966:16)
<...snip...>
I think this breakage will also affect other decorators.
Expected behavior
Hotkeys work as expected.
See https://codesandbox.io/s/q3jk1n66mj.
Possible solution
I tried using the following to get around this but didn't have much luck:
function WrappedApp(props: IAppProps) {
return new App(props);
}
WrappedApp.prototype = Object.create(App.prototype);
const AppWithHotkeys = HotkeysTarget(WrappedApp as any);
ReactDOM.render(<AppWithHotkeys {...(window as any).CONTEXT} />, document.getElementById('app'));
The render
call from HotkeysTarget
still never gets called.