@embeddable.com/sdk-react 2.2.2 → 2.2.4

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.
package/lib/index.js CHANGED
@@ -679,13 +679,25 @@ async function runViteBuild(ctx) {
679
679
  define: { "process.env.NODE_ENV": '"production"' },
680
680
  });
681
681
  }
682
- const REPLACE_TOKEN = "{{LAZY_IMPORTS}}";
682
+ const IMPORT_REPLACE_TOKEN = "{{LAZY_IMPORTS}}";
683
+ const ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN = "{{ERROR_FALLBACK_COMPONENT_IMPORT}}";
684
+ const ERROR_FALLBACK_COMPONENT_TOKEN = "{{ERROR_FALLBACK_COMPONENT}}";
685
+ const ERROR_FALLBACK_COMPONENT_DEFAULT_NAME = "ErrorFallbackComponent";
683
686
  async function injectImports(ctx, filesList) {
684
687
  const imports = filesList
685
688
  .map(([fileName, filePath]) => `\t${fileName}: React.lazy(() => import('./${path__namespace.relative(ctx.client.rootDir, filePath)}'))`)
686
689
  .join(",\n");
690
+ let errorBoundaryImport = "";
691
+ let errorFallbackComponent = "null";
692
+ if (ctx.client.errorFallbackComponent) {
693
+ errorBoundaryImport = `import ${ERROR_FALLBACK_COMPONENT_DEFAULT_NAME} from './${path__namespace.relative(ctx.client.rootDir, ctx.client.errorFallbackComponent)}';`;
694
+ errorFallbackComponent = ERROR_FALLBACK_COMPONENT_DEFAULT_NAME;
695
+ }
687
696
  const content = await fs__namespace$1.readFile(path__namespace.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
688
- await fs__namespace$1.writeFile(path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content.replace(REPLACE_TOKEN, imports));
697
+ await fs__namespace$1.writeFile(path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
698
+ .replace(IMPORT_REPLACE_TOKEN, imports)
699
+ .replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
700
+ .replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent));
689
701
  }
690
702
 
691
703
  var build = async (ctx) => {