benmerckx / genes

Generates split ES6 modules and Typescript definitions from Haxe modules.
43 stars 8 forks source link

Symbol definition missing in genes generated js code causing Uncaught ReferenceError #32

Closed cambiata closed 3 years ago

cambiata commented 3 years ago

When trying out genes together with haxe-react, I notice a that a symbol that is defined in the standard generated js output...

// index.js - standard haxe generated
. . .
var react_ReactMacro = function() { };

// the following line is part of the standard haxe js output:
var $$tre = (typeof Symbol === "function" && Symbol.for && Symbol.for("react.element")) || 0xeac7;  // <------

App.main();
})({});

...is missing in the genes generated output, causing a runtime "Uncaught ReferenceError: $$tre is not defined" error.

If I add this missing definition in the genes generated output like the following...

// index.js - genes generated
import { Register } from "./genes/Register.js"
import { App } from "./App.js"

// Manually adding the following line to genes generated js output solves the problem:
window.$$tre = (typeof Symbol === "function" && Symbol.for && Symbol.for("react.element")) || 0xeac7;

App.main()

...everything works fine.

So, it seems that the genes generator misses this $$tre definition - or at least never includes it in the generated code.

Any ideas how to solve this?

/ Jonas

benmerckx commented 3 years ago

There's some previous discussion here: https://github.com/benmerckx/genes/issues/13

Basically there's no right way to handle init when files are split that I know of. For this specific issue you can declare it yourself or use -D react_no_inline

benmerckx commented 3 years ago

See also: https://github.com/kLabz/haxe-react/issues/39

cambiata commented 3 years ago

Ah, didn't know of -D react_no_inline - it seems to work fine in my case. Thanks!