@builder.io/mitosis 0.3.13 → 0.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -332,16 +332,13 @@ var _componentToReact = function (json, options, isSubComponent) {
332
332
  if ((0, context_1.hasContext)(json) && options.contextType !== 'prop-drill') {
333
333
  reactLibImports.add('useContext');
334
334
  }
335
- if (allRefs.length) {
335
+ if (allRefs.length || ((_c = json.hooks.onInit) === null || _c === void 0 ? void 0 : _c.code)) {
336
336
  reactLibImports.add('useRef');
337
337
  }
338
338
  if (!options.preact && hasPropRef) {
339
339
  reactLibImports.add('forwardRef');
340
340
  }
341
- if (json.hooks.onMount.length ||
342
- ((_c = json.hooks.onUnMount) === null || _c === void 0 ? void 0 : _c.code) ||
343
- ((_d = json.hooks.onUpdate) === null || _d === void 0 ? void 0 : _d.length) ||
344
- ((_e = json.hooks.onInit) === null || _e === void 0 ? void 0 : _e.code)) {
341
+ if (json.hooks.onMount.length || ((_d = json.hooks.onUnMount) === null || _d === void 0 ? void 0 : _d.code) || ((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)) {
345
342
  reactLibImports.add('useEffect');
346
343
  }
347
344
  var hasCustomStyles = !!((_f = json.style) === null || _f === void 0 ? void 0 : _f.length);
@@ -388,10 +385,10 @@ var _componentToReact = function (json, options, isSubComponent) {
388
385
  })
389
386
  : "const state = useLocalProxy(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
390
387
  : '', hasStateArgument ? refsString : '', getContextString(json, options), ((_g = json.hooks.init) === null || _g === void 0 ? void 0 : _g.code) ? (0, state_2.processHookCode)({ str: (_h = json.hooks.init) === null || _h === void 0 ? void 0 : _h.code, options: options }) : '', contextStr || '', ((_j = json.hooks.onInit) === null || _j === void 0 ? void 0 : _j.code)
391
- ? "\n useEffect(() => {\n ".concat((0, state_2.processHookCode)({
388
+ ? "\n const hasInitialized = useRef(false);\n if (!hasInitialized.current) {\n ".concat((0, state_2.processHookCode)({
392
389
  str: json.hooks.onInit.code,
393
390
  options: options,
394
- }), "\n }, [])\n ")
391
+ }), "\n hasInitialized.current = true;\n }\n ")
395
392
  : '', json.hooks.onEvent
396
393
  .map(function (hook) {
397
394
  var eventName = "\"".concat(hook.eventName, "\"");
@@ -132,7 +132,7 @@ var DEFAULT_OPTIONS = {
132
132
  };
133
133
  var componentToSolid = function (passedOptions) {
134
134
  return function (_a) {
135
- var _b, _c, _d, _e, _f;
135
+ var _b, _c, _d, _e, _f, _g, _h;
136
136
  var component = _a.component;
137
137
  var json = (0, fast_clone_1.fastClone)(component);
138
138
  var options = (0, merge_options_1.initializeOptions)({
@@ -193,13 +193,13 @@ var componentToSolid = function (passedOptions) {
193
193
  var storeImports = (_e = state === null || state === void 0 ? void 0 : state.import.store) !== null && _e !== void 0 ? _e : [];
194
194
  var propType = json.propsTypeRef || 'any';
195
195
  var propsArgs = "props".concat(options.typescript ? ":".concat(propType) : '');
196
- var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(", ") {\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n\n return (", "\n ", "\n ", "\n ", "\n ", ")\n }\n\n export default ", ";\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(", ") {\n ", "\n\n ", "\n ", "\n\n ", "\n ", "\n\n return (", "\n ", "\n ", "\n ", "\n ", ")\n }\n\n export default ", ";\n "])), solidJSImports.length > 0 ? "import { ".concat(solidJSImports.join(', '), " } from 'solid-js';") : '', !foundDynamicComponents ? '' : "import { Dynamic } from 'solid-js/web';", storeImports.length > 0 ? "import { ".concat(storeImports.join(', '), " } from 'solid-js/store';") : '', componentHasStyles && options.stylesType === 'styled-components'
196
+ var str = (0, dedent_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(", ") {\n ", "\n\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n return (", "\n ", "\n ", "\n ", "\n ", ")\n }\n\n export default ", ";\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n function ", "(", ") {\n ", "\n\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n return (", "\n ", "\n ", "\n ", "\n ", ")\n }\n\n export default ", ";\n "])), solidJSImports.length > 0 ? "import { ".concat(solidJSImports.join(', '), " } from 'solid-js';") : '', !foundDynamicComponents ? '' : "import { Dynamic } from 'solid-js/web';", storeImports.length > 0 ? "import { ".concat(storeImports.join(', '), " } from 'solid-js/store';") : '', componentHasStyles && options.stylesType === 'styled-components'
197
197
  ? 'import { css } from "solid-styled-components";'
198
198
  : "", json.types && options.typescript ? json.types.join('\n') : '', (0, render_imports_1.renderPreComponent)({
199
199
  explicitImportFileExtension: options.explicitImportFileExtension,
200
200
  component: json,
201
201
  target: 'solid',
202
- }), json.name, propsArgs, (_f = state === null || state === void 0 ? void 0 : state.str) !== null && _f !== void 0 ? _f : '', getRefsString(json, options), getContextString(json, options), json.hooks.onMount.map(function (hook) { return "onMount(() => { ".concat(hook.code, " })"); }).join('\n'), json.hooks.onUpdate
202
+ }), json.name, propsArgs, (_f = state === null || state === void 0 ? void 0 : state.str) !== null && _f !== void 0 ? _f : '', getRefsString(json, options), getContextString(json, options), (_h = (_g = json.hooks.onInit) === null || _g === void 0 ? void 0 : _g.code) !== null && _h !== void 0 ? _h : '', json.hooks.onMount.map(function (hook) { return "onMount(() => { ".concat(hook.code, " })"); }).join('\n'), json.hooks.onUpdate
203
203
  ? json.hooks.onUpdate
204
204
  .map(function (hook, index) {
205
205
  // TO-DO: support `onUpdate` without `deps`
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "name": "Builder.io",
23
23
  "url": "https://www.builder.io"
24
24
  },
25
- "version": "0.3.13",
25
+ "version": "0.3.14",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {