@genesislcap/foundation-react-utils 15.18.0 → 15.19.0-DCD-4786.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-react-utils",
3
3
  "description": "Genesis Foundation React Utils",
4
- "version": "15.18.0",
4
+ "version": "15.19.0-DCD-4786.3",
5
5
  "sideEffects": false,
6
6
  "license": "SEE LICENSE IN license.txt",
7
7
  "main": "dist/esm/index.js",
@@ -47,13 +47,13 @@
47
47
  }
48
48
  },
49
49
  "devDependencies": {
50
- "@genesislcap/foundation-testing": "15.18.0",
51
- "@genesislcap/genx": "15.18.0",
52
- "@genesislcap/rollup-builder": "15.18.0",
53
- "@genesislcap/ts-builder": "15.18.0",
54
- "@genesislcap/uvu-playwright-builder": "15.18.0",
55
- "@genesislcap/vite-builder": "15.18.0",
56
- "@genesislcap/webpack-builder": "15.18.0",
50
+ "@genesislcap/foundation-testing": "15.19.0-DCD-4786.3",
51
+ "@genesislcap/genx": "15.19.0-DCD-4786.3",
52
+ "@genesislcap/rollup-builder": "15.19.0-DCD-4786.3",
53
+ "@genesislcap/ts-builder": "15.19.0-DCD-4786.3",
54
+ "@genesislcap/uvu-playwright-builder": "15.19.0-DCD-4786.3",
55
+ "@genesislcap/vite-builder": "15.19.0-DCD-4786.3",
56
+ "@genesislcap/webpack-builder": "15.19.0-DCD-4786.3",
57
57
  "react-router-dom": "^7.1.3"
58
58
  },
59
59
  "peerDependencies": {
@@ -67,10 +67,10 @@
67
67
  }
68
68
  },
69
69
  "dependencies": {
70
- "@genesislcap/foundation-forms": "15.18.0",
71
- "@genesislcap/foundation-layout": "15.18.0",
72
- "@genesislcap/foundation-logger": "15.18.0",
73
- "@genesislcap/web-core": "15.18.0",
70
+ "@genesislcap/foundation-forms": "15.19.0-DCD-4786.3",
71
+ "@genesislcap/foundation-layout": "15.19.0-DCD-4786.3",
72
+ "@genesislcap/foundation-logger": "15.19.0-DCD-4786.3",
73
+ "@genesislcap/web-core": "15.19.0-DCD-4786.3",
74
74
  "@jsonforms/core": "^3.2.1",
75
75
  "@r2wc/react-to-web-component": "^2.0.2"
76
76
  },
@@ -82,6 +82,5 @@
82
82
  "publishConfig": {
83
83
  "access": "public"
84
84
  },
85
- "customElements": "dist/custom-elements.json",
86
- "gitHead": "a92013873774dbc7f67a32d37994f10777f86383"
85
+ "customElements": "dist/custom-elements.json"
87
86
  }
@@ -1,4 +0,0 @@
1
- {
2
- "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "../../../api-extractor.json"
4
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=router.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"router.test.d.ts","sourceRoot":"","sources":["../../../src/router/router.test.ts"],"names":[],"mappings":""}
@@ -1,82 +0,0 @@
1
- import { assert, createLogicSuite } from '@genesislcap/foundation-testing';
2
- import { mergePbcRoutes } from './pbc-routes';
3
- import { buildPostLoginRedirect } from './post-login-redirect';
4
- import { createComponentRegistry } from './single-component';
5
- const RedirectSuite = createLogicSuite('buildPostLoginRedirect');
6
- RedirectSuite('falls back to `/` when there is no stashed origin', () => {
7
- assert.is(buildPostLoginRedirect({}), '/');
8
- assert.is(buildPostLoginRedirect({ state: null }), '/');
9
- assert.is(buildPostLoginRedirect({ state: {} }), '/');
10
- });
11
- RedirectSuite('honours a custom default path', () => {
12
- assert.is(buildPostLoginRedirect({}, '/home'), '/home');
13
- });
14
- RedirectSuite('returns the pathname when there is no search/hash', () => {
15
- assert.is(buildPostLoginRedirect({ state: { from: { pathname: '/grids' } } }), '/grids');
16
- });
17
- RedirectSuite('preserves search and hash so deep-link params survive', () => {
18
- assert.is(buildPostLoginRedirect({
19
- state: { from: { pathname: '/', search: '?component=Home', hash: '#top' } },
20
- }), '/?component=Home#top');
21
- });
22
- RedirectSuite.run();
23
- const RegistrySuite = createLogicSuite('createComponentRegistry');
24
- const Home = () => null;
25
- const GridsShowcase = () => null;
26
- const registry = createComponentRegistry({ Home, GridsShowcase });
27
- RegistrySuite('resolves an exact name', () => {
28
- assert.is(registry.resolve('Home'), Home);
29
- assert.is(registry.resolve('GridsShowcase'), GridsShowcase);
30
- });
31
- RegistrySuite('resolves case- and separator-insensitively', () => {
32
- assert.is(registry.resolve('home'), Home);
33
- assert.is(registry.resolve('gridsshowcase'), GridsShowcase);
34
- assert.is(registry.resolve('grids-showcase'), GridsShowcase);
35
- assert.is(registry.resolve('grids_showcase'), GridsShowcase);
36
- assert.is(registry.resolve('Grids Showcase'), GridsShowcase);
37
- });
38
- RegistrySuite('returns undefined for unknown or empty names', () => {
39
- assert.is(registry.resolve('nope'), undefined);
40
- assert.is(registry.resolve(null), undefined);
41
- assert.is(registry.resolve(undefined), undefined);
42
- assert.is(registry.resolve(''), undefined);
43
- });
44
- RegistrySuite('exposes the registered names via available()', () => {
45
- assert.equal(registry.available(), ['Home', 'GridsShowcase']);
46
- });
47
- RegistrySuite.run();
48
- const PbcSuite = createLogicSuite('mergePbcRoutes');
49
- PbcSuite('appends PBC routes after the static ones', () => {
50
- const staticRoutes = [{ path: '/home', element: null }];
51
- const merged = mergePbcRoutes(staticRoutes, [{ path: 'reporting' }], {
52
- renderPbc: () => 'pbc',
53
- });
54
- assert.is(merged.length, 2);
55
- assert.is(merged[0].path, '/home');
56
- assert.is(merged[1].path, '/reporting');
57
- assert.is(merged[1].element, 'pbc');
58
- });
59
- PbcSuite('carries pbc element/tag + navItems + settings through `data`', () => {
60
- var _a, _b, _c, _d;
61
- const navItems = [{ navId: 'header', title: 'Reporting' }];
62
- const el = () => 'loader';
63
- const merged = mergePbcRoutes([], [
64
- {
65
- path: 'reporting',
66
- element: el,
67
- elementTag: 'reporting-app',
68
- navItems,
69
- settings: { permissionCode: 'ReportView' },
70
- },
71
- ], { renderPbc: () => null });
72
- assert.is(merged[0].permissionCode, 'ReportView');
73
- assert.is((_a = merged[0].data) === null || _a === void 0 ? void 0 : _a.pbcElement, el);
74
- assert.is((_b = merged[0].data) === null || _b === void 0 ? void 0 : _b.pbcElementTag, 'reporting-app');
75
- assert.equal((_c = merged[0].data) === null || _c === void 0 ? void 0 : _c.navItems, navItems);
76
- assert.is((_d = merged[0].data) === null || _d === void 0 ? void 0 : _d.permissionCode, 'ReportView');
77
- });
78
- PbcSuite('returns only the static routes when there are no PBC routes', () => {
79
- const staticRoutes = [{ path: '/home', element: null }];
80
- assert.equal(mergePbcRoutes(staticRoutes, [], { renderPbc: () => null }), staticRoutes);
81
- });
82
- PbcSuite.run();
@@ -1 +0,0 @@
1
- {"root":["../src/create-grid-pro-cell-portals.tsx","../src/create-grid-pro-cell-renderer.ts","../src/create-react-renderer.ts","../src/index.ts","../src/react-layout-factory.tsx","../src/router/app-routes.tsx","../src/router/index.ts","../src/router/pbc-routes.ts","../src/router/post-login-redirect.ts","../src/router/protected-route.tsx","../src/router/router.test.ts","../src/router/single-component.tsx"],"version":"5.9.2"}
@@ -1,216 +0,0 @@
1
- import { createLogger } from '@genesislcap/foundation-logger';
2
- import {
3
- Component as ReactClassComponent,
4
- memo,
5
- useEffect,
6
- useSyncExternalStore,
7
- type ComponentType,
8
- type ReactNode,
9
- } from 'react';
10
- import { createPortal, flushSync } from 'react-dom';
11
-
12
- const logger = createLogger('foundation-react-utils');
13
-
14
- /**
15
- * A single mounted cell tracked by a {@link GridProCellPortals} manager.
16
- * @internal
17
- */
18
- interface CellPortalEntry {
19
- id: number;
20
- container: HTMLElement;
21
- Component: ComponentType<any>;
22
- params: any;
23
- }
24
-
25
- /**
26
- * Shared portal manager for Grid Pro React cell renderers.
27
- *
28
- * Created with {@link createGridProCellPortals}. Render the {@link GridProCellPortals.Portals}
29
- * component exactly once inside your React tree — cells rendered through this manager become
30
- * part of that tree, so they inherit React Context (Redux providers, theme, router, etc.) from
31
- * wherever `Portals` sits. Pass the manager to {@link createGridProCellRenderer} via the
32
- * `portals` option to opt a renderer into portal mode.
33
- *
34
- * @public
35
- */
36
- export interface GridProCellPortals {
37
- /**
38
- * Host component for all cells rendered through this manager. Render it exactly once,
39
- * inside every provider the cell renderers should inherit, and keep it mounted for as
40
- * long as the grid is on screen — unmounting it blanks all portal-rendered cells.
41
- */
42
- Portals: ComponentType;
43
- /**
44
- * Mounts a component into a cell container and returns the entry id.
45
- * Called by the cell renderer wrapper — not intended for direct use.
46
- * @internal
47
- */
48
- mount(container: HTMLElement, Component: ComponentType<any>, params: any): number;
49
- /**
50
- * Re-renders a mounted cell with new params.
51
- * Called by the cell renderer wrapper — not intended for direct use.
52
- * @internal
53
- */
54
- update(id: number, params: any): void;
55
- /**
56
- * Removes a mounted cell.
57
- * Called by the cell renderer wrapper — not intended for direct use.
58
- * @internal
59
- */
60
- remove(id: number): void;
61
- }
62
-
63
- /**
64
- * Error boundary around each portal-rendered cell. A shared React tree means one throwing
65
- * renderer would otherwise unmount every portal cell in the grid — this contains the blast
66
- * radius to the failing cell (which renders empty).
67
- * @internal
68
- */
69
- class CellPortalErrorBoundary extends ReactClassComponent<
70
- { children: ReactNode },
71
- { failed: boolean }
72
- > {
73
- public override state = { failed: false };
74
-
75
- public static getDerivedStateFromError() {
76
- return { failed: true };
77
- }
78
-
79
- public override componentDidCatch(error: unknown) {
80
- logger.error('Grid Pro portal cell renderer threw during render:', error);
81
- }
82
-
83
- public override render() {
84
- return this.state.failed ? null : this.props.children;
85
- }
86
- }
87
-
88
- /**
89
- * One portal per cell. Memoised on the entry object — `update()` swaps the entry, so only
90
- * the changed cell reconciles when the manager re-renders.
91
- * @internal
92
- */
93
- const CellPortal = memo(function GridProCellPortal({ entry }: { entry: CellPortalEntry }) {
94
- return createPortal(
95
- <CellPortalErrorBoundary>
96
- <entry.Component {...entry.params} />
97
- </CellPortalErrorBoundary>,
98
- entry.container,
99
- );
100
- });
101
-
102
- /**
103
- * Creates a {@link GridProCellPortals} manager: a single React root shared by every cell
104
- * renderer registered with it, with each cell rendered into its grid cell via a portal.
105
- *
106
- * Use this instead of the default one-root-per-cell mode when cell renderers need to
107
- * inherit React Context from the application tree (Redux, theme, router, query clients...)
108
- * — portal-rendered cells live in the tree where `Portals` is rendered, so context updates
109
- * propagate into visible cells like any other React state.
110
- *
111
- * @example
112
- * ```tsx
113
- * const cellPortals = createGridProCellPortals();
114
- *
115
- * const gridOptions = {
116
- * components: {
117
- * priceCell: createGridProCellRenderer(PriceCell, { portals: cellPortals }),
118
- * },
119
- * columnDefs: [{ field: 'price', cellRenderer: 'priceCell' }],
120
- * };
121
- *
122
- * function Page() {
123
- * return (
124
- * <SomeProvider>
125
- * <cellPortals.Portals />
126
- * <RapidGridPro gridOptions={gridOptions} />
127
- * </SomeProvider>
128
- * );
129
- * }
130
- * ```
131
- *
132
- * @remarks
133
- * Trade-offs versus the default per-cell roots: all cells registered with one manager share
134
- * a React tree, so a renderer that throws is contained by a per-cell error boundary (the
135
- * failing cell renders empty rather than crashing the rest), and unmounting `Portals` while
136
- * the grid is alive blanks every portal-rendered cell. Cell mounts are committed
137
- * synchronously (so AG Grid measures real content), which re-renders the manager once per
138
- * created cell — the per-cell portals are memoised, keeping that cheap at grid-pro's
139
- * virtualised cell counts.
140
- *
141
- * @public
142
- */
143
- export function createGridProCellPortals(): GridProCellPortals {
144
- let entries: readonly CellPortalEntry[] = [];
145
- let nextId = 0;
146
- let portalsMounted = false;
147
- const listeners = new Set<() => void>();
148
-
149
- const emit = () => {
150
- listeners.forEach((listener) => listener());
151
- };
152
-
153
- /**
154
- * Commits a store change synchronously so the cell content exists in the DOM before
155
- * AG Grid measures the container (autoHeight, autoSizeColumns, sizeColumnsToFit).
156
- * Mount runs from AG Grid's own (non-React) call stack, so flushing is safe; if it
157
- * ever runs inside a host React render, React warns and defers the flush instead.
158
- */
159
- const emitSync = () => {
160
- if (!portalsMounted) {
161
- emit();
162
- return;
163
- }
164
- flushSync(emit);
165
- };
166
-
167
- const subscribe = (listener: () => void) => {
168
- listeners.add(listener);
169
- return () => {
170
- listeners.delete(listener);
171
- };
172
- };
173
- const getSnapshot = () => entries;
174
-
175
- const Portals: ComponentType = () => {
176
- const snapshot = useSyncExternalStore(subscribe, getSnapshot);
177
- useEffect(() => {
178
- portalsMounted = true;
179
- return () => {
180
- portalsMounted = false;
181
- };
182
- }, []);
183
- return (
184
- <>
185
- {snapshot.map((entry) => (
186
- <CellPortal key={entry.id} entry={entry} />
187
- ))}
188
- </>
189
- );
190
- };
191
-
192
- return {
193
- Portals,
194
- mount(container, Component, params) {
195
- nextId += 1;
196
- const id = nextId;
197
- entries = [...entries, { id, container, Component, params }];
198
- emitSync();
199
- return id;
200
- },
201
- update(id, params) {
202
- entries = entries.map((entry) => (entry.id === id ? { ...entry, params } : entry));
203
- // Async on purpose: refresh() has already returned true and AG Grid does not
204
- // re-measure on refresh, so there is nothing to commit synchronously for.
205
- emit();
206
- },
207
- remove(id) {
208
- entries = entries.filter((entry) => entry.id !== id);
209
- // AG Grid can destroy cells synchronously while React is rendering (e.g. React
210
- // Router unmounting the page hosting the grid); notifying subscribers there would
211
- // set state mid-render, so defer with a macrotask — the container is already
212
- // detached by AG Grid, so the portal lingering one tick is invisible.
213
- setTimeout(emit);
214
- },
215
- };
216
- }
@@ -1,235 +0,0 @@
1
- import { createLogger } from '@genesislcap/foundation-logger';
2
- import { createElement, type ComponentType } from 'react';
3
- import { flushSync } from 'react-dom';
4
- import { createRoot, type Root } from 'react-dom/client';
5
- import type { GridProCellPortals } from './create-grid-pro-cell-portals';
6
-
7
- const logger = createLogger('foundation-react-utils');
8
-
9
- /**
10
- * Props passed to a React component used as a Grid Pro cell renderer.
11
- *
12
- * This is a structural subset of AG Grid's `ICellRendererParams` — the full params object
13
- * (including any custom `cellRendererParams` from the column definition) is spread onto the
14
- * component as props on every render, so anything available on `ICellRendererParams` is
15
- * available here. Declared locally to avoid coupling this package to a specific
16
- * `ag-grid-community` version.
17
- *
18
- * @public
19
- */
20
- export interface GridProCellRendererProps<TData = any, TValue = any> {
21
- /** The cell value. */
22
- value: TValue;
23
- /** Value formatted by the column's value formatter, if any. */
24
- valueFormatted?: string | null;
25
- /** The full row data. */
26
- data: TData;
27
- /** The AG Grid row node. */
28
- node: any;
29
- /** The AG Grid api. */
30
- api: any;
31
- /** The row index of the cell. */
32
- rowIndex: number;
33
- /** The grid context object, as supplied via `gridOptions.context`. */
34
- context?: any;
35
- /** The column this cell belongs to. */
36
- column?: any;
37
- /** The column definition. */
38
- colDef?: any;
39
- /** Custom params from `cellRendererParams` and any other AG Grid params. */
40
- [key: string]: any;
41
- }
42
-
43
- /**
44
- * Options for {@link createGridProCellRenderer}.
45
- *
46
- * @public
47
- */
48
- export interface GridProCellRendererOptions {
49
- /**
50
- * When true (the default), the cell container is styled as a full-size flex row
51
- * (`display: flex; align-items: center; height: 100%; width: 100%`) so content is
52
- * vertically centred like grid-pro's built-in renderers.
53
- *
54
- * Set to false to leave the container unstyled and let the cell's own layout apply.
55
- * Do this when the forced flex/height layout gets in the way, e.g.:
56
- * - `autoHeight`/`wrapText` columns — `height: 100%` is circular when the row height
57
- * derives from the content, so the cell can collapse instead of growing;
58
- * - right-aligned numeric cells relying on `text-align` (a flex item packs to the start);
59
- * - content using `text-overflow: ellipsis` (a flex item won't truncate without
60
- * `min-width: 0`).
61
- */
62
- fillCell?: boolean;
63
-
64
- /**
65
- * Render cells through a shared {@link GridProCellPortals} manager instead of giving each
66
- * cell its own React root. Portal-rendered cells become part of the React tree where the
67
- * manager's `Portals` component is rendered, so they inherit React Context (Redux, theme,
68
- * router, etc.) from the application — the main limitation of the default mode.
69
- *
70
- * Create one with `createGridProCellPortals()` and render `<manager.Portals />` once,
71
- * inside the providers the cells should see. When omitted (the default), each cell gets
72
- * its own isolated root.
73
- */
74
- portals?: GridProCellPortals;
75
- }
76
-
77
- /**
78
- * The subset of AG Grid's `ICellRendererComp` contract implemented by the wrapper class
79
- * returned from {@link createGridProCellRenderer}.
80
- *
81
- * @public
82
- */
83
- export interface GridProReactCellRenderer {
84
- init(params: GridProCellRendererProps): void;
85
- getGui(): HTMLElement;
86
- refresh(params: GridProCellRendererProps): boolean;
87
- destroy(): void;
88
- }
89
-
90
- /**
91
- * Wraps a React component as an AG Grid cell renderer component class for use with
92
- * `grid-pro` / `grid-pro-beta` (`<foundation-grid-pro>` / `<rapid-grid-pro>`).
93
- *
94
- * Grid Pro is a framework-agnostic Web Component, so AG Grid inside it only understands
95
- * plain-JS component classes. This helper bridges the gap: it returns a class implementing
96
- * `ICellRendererComp` that mounts the React component into the cell with its own React root,
97
- * re-renders it on `refresh` (so value changes and cell flashing keep working without
98
- * remounting), and unmounts it when the cell is destroyed.
99
- *
100
- * The component receives the full AG Grid `ICellRendererParams` object as props — including
101
- * `value`, `data`, `node`, `api` and anything supplied via the column's `cellRendererParams`.
102
- * Hooks and local state inside the component work as normal.
103
- *
104
- * Note on React Context/Redux: by default each cell is rendered into its own independent
105
- * React root, so renderers do NOT inherit contexts (Redux providers, theme context, React
106
- * Router, etc.) from the application tree hosting the grid. Either pass data/callbacks
107
- * explicitly via `cellRendererParams`, or opt into portal mode with the `portals` option
108
- * (see {@link GridProCellRendererOptions.portals} and `createGridProCellPortals`) — portal
109
- * cells share the application tree and inherit its contexts.
110
- *
111
- * Note on `key`: props are passed by spreading the AG Grid params object, and React reserves
112
- * `key` — a `cellRendererParams` entry named `key` is consumed as the element key and never
113
- * reaches the component, so avoid that name. (`ref` is fine: React 19 forwards it to function
114
- * components as a regular prop.)
115
- *
116
- * Note on styling: cells render inside grid-pro's shadow root, so document-level stylesheets
117
- * (CSS files imported by your app/page) do NOT reach the rendered component. Style renderers
118
- * with inline styles or CSS-in-JS. Design-system tokens remain usable either way — CSS custom
119
- * properties inherit across shadow boundaries (e.g. `color: 'var(--accent-fill-rest)'`).
120
- *
121
- * @example
122
- * ```tsx
123
- * import { createGridProCellRenderer, type GridProCellRendererProps } from '@genesislcap/foundation-react-utils';
124
- *
125
- * function PriceCell({ value }: GridProCellRendererProps) {
126
- * return <span style={{ color: value >= 0 ? 'green' : 'red' }}>{value}</span>;
127
- * }
128
- *
129
- * const gridOptions = {
130
- * components: {
131
- * priceCell: createGridProCellRenderer(PriceCell),
132
- * },
133
- * columnDefs: [
134
- * { field: 'price', cellRenderer: 'priceCell' },
135
- * ],
136
- * };
137
- *
138
- * // <rapid-grid-pro gridOptions={gridOptions} /> — or register via the grid's
139
- * // `gridComponents` property to make the renderer available across all columns.
140
- * ```
141
- *
142
- * @param Component - The React component to render inside the cell.
143
- * @param options - Optional {@link GridProCellRendererOptions} to tune the wrapper behaviour.
144
- * @returns A cell renderer component class registrable via `gridOptions.components`,
145
- * the grid's `gridComponents` property, or directly as a column's `cellRenderer`.
146
- *
147
- * @public
148
- */
149
- export function createGridProCellRenderer<
150
- P extends GridProCellRendererProps = GridProCellRendererProps,
151
- >(
152
- Component: ComponentType<P>,
153
- options: GridProCellRendererOptions = {},
154
- ): new () => GridProReactCellRenderer {
155
- const fillCell = options.fillCell !== false;
156
- const portals = options.portals;
157
-
158
- return class ReactCellRenderer implements GridProReactCellRenderer {
159
- private container!: HTMLElement;
160
- private root: Root | null = null;
161
- private portalId: number | null = null;
162
-
163
- public init(params: P): void {
164
- this.container = document.createElement('div');
165
- if (fillCell) {
166
- // Fill the cell so the React content can align itself like native renderers do.
167
- // See GridProCellRendererOptions.fillCell for when to opt out.
168
- this.container.style.display = 'flex';
169
- this.container.style.alignItems = 'center';
170
- this.container.style.height = '100%';
171
- this.container.style.width = '100%';
172
- }
173
-
174
- if (portals) {
175
- // Portal mode: the shared manager renders the component into this container as
176
- // part of the application tree (mount commits synchronously so AG Grid measures
177
- // real content — same reasoning as the flushSync below).
178
- this.portalId = portals.mount(this.container, Component, params);
179
- return;
180
- }
181
-
182
- this.root = createRoot(this.container);
183
- // React 19 concurrent roots only *schedule* render(), but AG Grid inserts and can
184
- // synchronously measure the container as soon as init/getGui return (autoHeight,
185
- // autoSizeColumns, sizeColumnsToFit) — flush the first render so the grid measures
186
- // real content instead of an empty div (also avoids a one-frame empty flash).
187
- // Cell init runs from AG Grid's own (non-React) call stack, so flushing is safe
188
- // here; if it ever runs inside a host React render, React warns and falls back to
189
- // a deferred flush rather than breaking. refresh() intentionally stays async.
190
- flushSync(() => {
191
- this.root!.render(createElement(Component, params));
192
- });
193
- }
194
-
195
- public getGui(): HTMLElement {
196
- return this.container;
197
- }
198
-
199
- public refresh(params: P): boolean {
200
- if (portals) {
201
- if (this.portalId != null) {
202
- portals.update(this.portalId, params);
203
- }
204
- return true;
205
- }
206
- this.root?.render(createElement(Component, params));
207
- return true;
208
- }
209
-
210
- public destroy(): void {
211
- if (portals) {
212
- if (this.portalId != null) {
213
- portals.remove(this.portalId);
214
- this.portalId = null;
215
- }
216
- return;
217
- }
218
-
219
- const root = this.root;
220
- this.root = null;
221
- if (root) {
222
- // AG Grid can destroy cells synchronously while React is rendering (e.g. React Router
223
- // unmounting the page that hosts the grid). Unmounting a root mid-render is not allowed,
224
- // and microtasks still run inside the render cycle — defer with a macrotask instead.
225
- setTimeout(() => {
226
- try {
227
- root.unmount();
228
- } catch (error) {
229
- logger.error('Error unmounting React root in Grid Pro cell renderer:', error);
230
- }
231
- });
232
- }
233
- }
234
- };
235
- }