@opentui/react 0.6.5 → 0.6.7

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.
@@ -134,15 +134,15 @@ import { Fragment, jsxDEV } from "react/jsx-dev-runtime";
134
134
 
135
135
  // src/components/error-boundary.tsx
136
136
  class ErrorBoundary extends React.Component {
137
- constructor(props) {
138
- super(props);
139
- this.state = { hasError: false, error: null };
137
+ state = { error: null };
138
+ static getDerivedStateFromProps(props, state) {
139
+ return props.resetKey === state.resetKey ? null : { error: null, resetKey: props.resetKey };
140
140
  }
141
141
  static getDerivedStateFromError(error) {
142
- return { hasError: true, error };
142
+ return { error };
143
143
  }
144
144
  render() {
145
- if (this.state.hasError && this.state.error) {
145
+ if (this.state.error) {
146
146
  return /* @__PURE__ */ jsxDEV("box", {
147
147
  style: { flexDirection: "column", padding: 2 },
148
148
  children: /* @__PURE__ */ jsxDEV("text", {
@@ -164,7 +164,7 @@ import { ImageRenderable as ImageRenderable2, TextNodeRenderable as TextNodeRend
164
164
  // package.json
165
165
  var package_default = {
166
166
  name: "@opentui/react",
167
- version: "0.6.5",
167
+ version: "0.6.7",
168
168
  description: "React renderer for building terminal user interfaces using OpenTUI core",
169
169
  license: "MIT",
170
170
  repository: {
@@ -565,10 +565,8 @@ $ bun add react-devtools-core@7 -d
565
565
  }
566
566
  }
567
567
  reconciler.injectIntoDevTools();
568
- function _render(element, root) {
569
- const container = reconciler.createContainer(root, ConcurrentRoot, null, false, null, "", console.error, console.error, console.error, () => {});
570
- reconciler.updateContainer(element, container, null, () => {});
571
- return container;
568
+ function createContainer(root) {
569
+ return reconciler.createContainer(root, ConcurrentRoot, null, false, null, "", console.error, console.error, console.error, () => {});
572
570
  }
573
571
 
574
572
  // src/reconciler/renderer.ts
@@ -577,21 +575,28 @@ var flushSync2 = _r.flushSyncFromReconciler ?? _r.flushSync;
577
575
  var { createPortal: createPortal2 } = reconciler;
578
576
  function createRoot2(renderer) {
579
577
  let container = null;
578
+ let renderVersion = 0;
579
+ const appContext = { keyHandler: renderer.keyInput, renderer };
580
580
  const cleanup = () => {
581
- if (container) {
582
- reconciler.updateContainer(null, container, null, () => {});
583
- reconciler.flushSyncWork();
584
- container = null;
585
- }
581
+ const current = container;
582
+ if (!current)
583
+ return;
584
+ container = null;
585
+ renderer.off(CliRenderEvents.DESTROY, cleanup);
586
+ reconciler.updateContainerSync(null, current, null, () => {});
587
+ reconciler.flushSyncWork();
586
588
  };
587
- if (!renderer.isDestroyed)
588
- renderer.once(CliRenderEvents.DESTROY, cleanup);
589
589
  return {
590
590
  render: (node) => {
591
591
  if (renderer.isDestroyed)
592
592
  return;
593
593
  engine.attach(renderer);
594
- container = _render(React2.createElement(AppContext2.Provider, { value: { keyHandler: renderer.keyInput, renderer } }, React2.createElement(ErrorBoundary, null, node)), renderer.root);
594
+ if (!container) {
595
+ container = createContainer(renderer.root);
596
+ renderer.once(CliRenderEvents.DESTROY, cleanup);
597
+ }
598
+ const element = React2.createElement(AppContext2.Provider, { value: appContext }, React2.createElement(ErrorBoundary, { resetKey: ++renderVersion, children: node }));
599
+ reconciler.updateContainer(element, container, null, () => {});
595
600
  },
596
601
  unmount: cleanup
597
602
  };
package/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  flushSync2,
12
12
  createPortal2,
13
13
  createRoot2
14
- } from "./chunk-9z09jsmz.js";
14
+ } from "./chunk-sqvm7kwh.js";
15
15
  // src/hooks/use-blur.ts
16
16
  import { useEffect } from "react";
17
17
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "type": "module",
7
- "version": "0.6.5",
7
+ "version": "0.6.7",
8
8
  "description": "React renderer for building terminal user interfaces using OpenTUI core",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -52,7 +52,7 @@
52
52
  }
53
53
  },
54
54
  "dependencies": {
55
- "@opentui/core": "0.6.5",
55
+ "@opentui/core": "0.6.7",
56
56
  "react-reconciler": "^0.33.0"
57
57
  },
58
58
  "devDependencies": {
@@ -1,16 +1,16 @@
1
1
  import React from "react";
2
- export declare class ErrorBoundary extends React.Component<{
2
+ type ErrorBoundaryProps = {
3
3
  children: React.ReactNode;
4
- }, {
5
- hasError: boolean;
4
+ resetKey: number;
5
+ };
6
+ type ErrorBoundaryState = {
6
7
  error: Error | null;
7
- }> {
8
- constructor(props: {
9
- children: React.ReactNode;
10
- });
11
- static getDerivedStateFromError(error: Error): {
12
- hasError: boolean;
13
- error: Error;
14
- };
8
+ resetKey?: number;
9
+ };
10
+ export declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
11
+ state: ErrorBoundaryState;
12
+ static getDerivedStateFromProps(props: ErrorBoundaryProps, state: ErrorBoundaryState): ErrorBoundaryState | null;
13
+ static getDerivedStateFromError(error: Error): Partial<ErrorBoundaryState>;
15
14
  render(): any;
16
15
  }
16
+ export {};
@@ -1,5 +1,4 @@
1
1
  import type { RootRenderable } from "@opentui/core";
2
- import React from "react";
3
2
  import ReactReconciler from "react-reconciler";
4
3
  export declare const reconciler: ReactReconciler.Reconciler<RootRenderable, import("@opentui/core").BaseRenderable, import("@opentui/core").TextNodeRenderable, unknown, unknown, import("@opentui/core").BaseRenderable>;
5
- export declare function _render(element: React.ReactNode, root: RootRenderable): any;
4
+ export declare function createContainer(root: RootRenderable): any;
package/test-utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  createRoot2
4
- } from "./chunk-9z09jsmz.js";
4
+ } from "./chunk-sqvm7kwh.js";
5
5
 
6
6
  // src/test-utils.ts
7
7
  import { createTestRenderer } from "@opentui/core/testing";