EnxDev commented on code in PR #44907:
URL: https://github.com/apache/superset/pull/44907#discussion_r4170147627


##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/renderers/TextCellRenderer.tsx:
##########
@@ -51,6 +61,24 @@ export const TextCellRenderer = (params: CellRendererProps) 
=> {
     }
   }
 
+  // Object and array JSON is interactive. Plain text, URLs, and opt-in HTML
+  // stay on the paths below.
+  const parsedJson = parseJsonCellValue(value);
+  if (parsedJson) {

Review Comment:
   This branch isn't gated on `jsonInCell`, so every existing AG Grid chart 
with JSON text gets the button renderer on upgrade. That button carries 
`data-json-cell-action`, so `handleCellClicked` bails and a click on a JSON 
dimension cell stops emitting a cross-filter (and stops selecting the row), on 
dashboards whose owners never touched the new checkbox.
   
   Could the default path stay plain text and only switch over when 
`jsonInCell` is on? If the dialog-on-click is meant to be the new default, it 
probably shouldn't swallow the cross-filter click.



##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/renderers/JsonCellRenderer.tsx:
##########
@@ -0,0 +1,589 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  type ReactNode,
+  useCallback,
+  useEffect,
+  useLayoutEffect,
+  useRef,
+  useState,
+} from 'react';
+import { t } from '@apache-superset/core/translation';
+import { styled } from '@apache-superset/core/theme';
+import { Button, Icons, Modal } from '@superset-ui/core/components';
+import { type JsonContainer, jsonCellPreview } from './parseJsonCellValue';
+import { syncJsonCellRowHeight } from './jsonCellRowHeight';
+
+const MAX_JSON_DEPTH = 32;
+const JSON_CELL_ROW_CHROME_PX = 12;
+const ARROW_CLICK_MS = 250;
+
+type JsonCellGridApi = {
+  resetRowHeights?: () => void;
+  onRowHeightChanged?: () => void;
+  isDestroyed?: () => boolean;
+};
+
+type JsonCellRowNode = {
+  setRowHeight?: (height: number | null | undefined) => void;
+};
+
+export type JsonCellRendererProps = {
+  value: JsonContainer;
+  rawText?: string;
+  colId: string;
+  autoHeight: boolean;
+  jsonInCell?: boolean;
+  api?: JsonCellGridApi;
+  node?: JsonCellRowNode;
+  eGridCell?: HTMLElement | null;
+};
+
+const Root = styled.div`
+  ${({ theme }) => `
+    display: flex;
+    flex-direction: column;
+    gap: ${theme.sizeUnit / 2}px;
+    width: 100%;
+    min-width: 0;
+    white-space: inherit;
+    word-break: inherit;
+  `}
+`;
+
+const Toolbar = styled.div`
+  ${({ theme }) => `
+    display: flex;
+    align-items: center;
+    gap: ${theme.sizeUnit}px;
+    min-width: 0;
+  `}
+`;
+
+const Preview = styled.span`
+  overflow: hidden;
+  text-overflow: ellipsis;
+  white-space: nowrap;
+  flex: 1;
+  min-width: 0;
+`;
+
+const JsonToggle = styled.button`
+  ${({ theme }) => `
+    display: inline-flex;
+    align-items: center;
+    justify-content: center;
+    width: ${theme.sizeUnit * 4}px;
+    height: ${theme.sizeUnit * 4}px;
+    padding: 0;
+    border: none;
+    background: transparent;
+    color: ${theme.colorTextSecondary};
+    cursor: pointer;
+    flex: none;
+
+    &:hover,
+    &:focus-visible {
+      color: ${theme.colorPrimary};
+    }
+  `}
+`;
+
+const TextToggle = styled.button`
+  display: block;
+  width: 100%;
+  min-width: 0;
+  padding: 0;
+  border: none;
+  background: transparent;
+  color: inherit;
+  font: inherit;
+  text-align: inherit;
+  cursor: pointer;
+  white-space: inherit;
+  word-break: inherit;
+`;
+
+const JsonBlock = styled.div`
+  ${({ theme }) => `
+    display: flex;
+    flex-direction: column;
+    min-width: 0;
+    font-family: ${theme.fontFamilyCode};
+  `}
+`;
+
+const JsonLine = styled.div`
+  display: flex;
+  align-items: flex-start;
+  gap: 4px;
+  min-width: 0;
+`;
+
+const JsonIndent = styled.div`
+  ${({ theme }) => `
+    padding-left: ${theme.sizeUnit * 4}px;
+  `}
+`;
+
+const JsonKey = styled.span`
+  ${({ theme }) => `
+    color: ${theme.colorText};
+    flex: none;
+  `}
+`;
+
+const JsonMuted = styled.span`
+  ${({ theme }) => `
+    color: ${theme.colorTextSecondary};
+  `}
+`;
+
+const StringValue = styled.span`
+  ${({ theme }) => `
+    color: ${theme.colorSuccess};
+  `}
+`;
+
+const NumberValue = styled.span`
+  ${({ theme }) => `
+    color: ${theme.colorPrimary};
+  `}
+`;
+
+const BooleanValue = styled.span`
+  ${({ theme }) => `
+    color: ${theme.colorWarning};
+  `}
+`;
+
+const Tree = styled.div`
+  ${({ theme }) => `
+    font-family: ${theme.fontFamilyCode};
+    font-size: ${theme.fontSizeSM}px;
+    white-space: pre-wrap;
+    word-break: break-word;
+  `}
+`;
+
+// AG Grid selects the row from a listener on the row container. React's
+// delegated click handler runs at the React root, after that listener, so the
+// control stops the native event on the button itself.
+const AG_GRID_STOP_PROPAGATION = '__ag_Grid_Stop_Propagation';
+
+function stopGridPointer(event: Event) {
+  event.stopPropagation();
+  Object.assign(event, { [AG_GRID_STOP_PROPAGATION]: true });
+}
+
+function JsonActionButton({
+  label,
+  expanded,
+  onActivate,
+  plain = false,
+  testId,
+  children,
+}: {
+  label?: string;
+  expanded?: boolean;
+  onActivate: () => void;
+  plain?: boolean;
+  testId?: string;
+  children: ReactNode;
+}) {
+  const ref = useRef<HTMLButtonElement>(null);
+
+  useLayoutEffect(() => {
+    const node = ref.current;
+    if (!node) {
+      return undefined;
+    }
+    const stop = (event: Event) => {
+      stopGridPointer(event);
+    };
+    const onClick = (event: Event) => {
+      stopGridPointer(event);
+      onActivate();
+    };
+    node.addEventListener('pointerdown', stop);
+    node.addEventListener('mousedown', stop);
+    node.addEventListener('click', onClick);
+    node.addEventListener('dblclick', stop);
+    return () => {
+      node.removeEventListener('pointerdown', stop);
+      node.removeEventListener('mousedown', stop);
+      node.removeEventListener('click', onClick);
+      node.removeEventListener('dblclick', stop);
+    };
+  }, [onActivate]);
+
+  const Toggle = plain ? TextToggle : JsonToggle;
+  return (
+    <Toggle
+      ref={ref}
+      type="button"
+      aria-expanded={expanded}
+      aria-label={label}
+      data-json-cell-action
+      data-test={testId}
+    >
+      {children}
+    </Toggle>
+  );
+}
+
+function JsonPrimitive({ value }: { value: unknown }) {
+  if (typeof value === 'string') {
+    return <StringValue>{JSON.stringify(value)}</StringValue>;
+  }
+  if (typeof value === 'number' || typeof value === 'bigint') {
+    return <NumberValue>{String(value)}</NumberValue>;
+  }
+  if (typeof value === 'boolean') {
+    return <BooleanValue>{String(value)}</BooleanValue>;
+  }
+  if (value === null) {
+    return <JsonMuted>null</JsonMuted>;
+  }
+  return <JsonMuted>{String(value)}</JsonMuted>;
+}
+
+function containerEntries(
+  value: JsonContainer,
+): Array<readonly [string, unknown]> {
+  if (Array.isArray(value)) {
+    return value.map((item, index) => [String(index), item] as const);
+  }
+  return Object.entries(value);
+}
+
+function containerSummary(value: JsonContainer): string {
+  if (Array.isArray(value)) {
+    return t('%s items', value.length);

Review Comment:
   This reads "1 items" / "1 keys" for single-entry containers, and translators 
can't pluralize it either.
   
   `tn('%s item', '%s items', value.length, value.length)` (and the same for 
keys) fixes both.



##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/renderers/JsonCellRenderer.tsx:
##########
@@ -0,0 +1,589 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  type ReactNode,
+  useCallback,
+  useEffect,
+  useLayoutEffect,
+  useRef,
+  useState,
+} from 'react';
+import { t } from '@apache-superset/core/translation';
+import { styled } from '@apache-superset/core/theme';
+import { Button, Icons, Modal } from '@superset-ui/core/components';
+import { type JsonContainer, jsonCellPreview } from './parseJsonCellValue';
+import { syncJsonCellRowHeight } from './jsonCellRowHeight';
+
+const MAX_JSON_DEPTH = 32;
+const JSON_CELL_ROW_CHROME_PX = 12;
+const ARROW_CLICK_MS = 250;
+
+type JsonCellGridApi = {
+  resetRowHeights?: () => void;
+  onRowHeightChanged?: () => void;
+  isDestroyed?: () => boolean;
+};
+
+type JsonCellRowNode = {
+  setRowHeight?: (height: number | null | undefined) => void;
+};
+
+export type JsonCellRendererProps = {
+  value: JsonContainer;
+  rawText?: string;
+  colId: string;
+  autoHeight: boolean;
+  jsonInCell?: boolean;
+  api?: JsonCellGridApi;
+  node?: JsonCellRowNode;
+  eGridCell?: HTMLElement | null;
+};
+
+const Root = styled.div`
+  ${({ theme }) => `
+    display: flex;
+    flex-direction: column;
+    gap: ${theme.sizeUnit / 2}px;
+    width: 100%;
+    min-width: 0;
+    white-space: inherit;
+    word-break: inherit;
+  `}
+`;
+
+const Toolbar = styled.div`
+  ${({ theme }) => `
+    display: flex;
+    align-items: center;
+    gap: ${theme.sizeUnit}px;
+    min-width: 0;
+  `}
+`;
+
+const Preview = styled.span`
+  overflow: hidden;
+  text-overflow: ellipsis;
+  white-space: nowrap;
+  flex: 1;
+  min-width: 0;
+`;
+
+const JsonToggle = styled.button`
+  ${({ theme }) => `
+    display: inline-flex;
+    align-items: center;
+    justify-content: center;
+    width: ${theme.sizeUnit * 4}px;
+    height: ${theme.sizeUnit * 4}px;
+    padding: 0;
+    border: none;
+    background: transparent;
+    color: ${theme.colorTextSecondary};
+    cursor: pointer;
+    flex: none;
+
+    &:hover,
+    &:focus-visible {
+      color: ${theme.colorPrimary};
+    }
+  `}
+`;
+
+const TextToggle = styled.button`
+  display: block;
+  width: 100%;
+  min-width: 0;
+  padding: 0;
+  border: none;
+  background: transparent;
+  color: inherit;
+  font: inherit;
+  text-align: inherit;
+  cursor: pointer;
+  white-space: inherit;
+  word-break: inherit;
+`;
+
+const JsonBlock = styled.div`
+  ${({ theme }) => `
+    display: flex;
+    flex-direction: column;
+    min-width: 0;
+    font-family: ${theme.fontFamilyCode};
+  `}
+`;
+
+const JsonLine = styled.div`
+  display: flex;
+  align-items: flex-start;
+  gap: 4px;
+  min-width: 0;
+`;

Review Comment:
   Nit, take it or leave it. The rest of the file pulls spacing off the theme, 
this one's a literal `4px`.
   
   ```suggestion
   const JsonLine = styled.div`
     ${({ theme }) => `
       display: flex;
       align-items: flex-start;
       gap: ${theme.sizeUnit}px;
       min-width: 0;
     `}
   `;
   ```



##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/renderers/parseJsonCellValue.ts:
##########
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export type JsonContainer = Record<string, unknown> | unknown[];
+
+// Skip multi-megabyte cells so a single value cannot stall the grid while
+// it is being parsed on the render path.
+const MAX_JSON_CELL_LENGTH = 5_000_000;
+

Review Comment:
   This runs `JSON.parse` synchronously for every visible text cell on every 
render and refresh, with no caching, and 5 MB is a big ceiling for that path.
   
   Worth dropping the cap to something like 100 KB (the dialog can still show 
the raw text above it), or memoizing the parse per string?



##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/renderers/JsonCellRenderer.tsx:
##########
@@ -0,0 +1,589 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  type ReactNode,
+  useCallback,
+  useEffect,
+  useLayoutEffect,
+  useRef,
+  useState,
+} from 'react';
+import { t } from '@apache-superset/core/translation';
+import { styled } from '@apache-superset/core/theme';
+import { Button, Icons, Modal } from '@superset-ui/core/components';
+import { type JsonContainer, jsonCellPreview } from './parseJsonCellValue';
+import { syncJsonCellRowHeight } from './jsonCellRowHeight';
+
+const MAX_JSON_DEPTH = 32;
+const JSON_CELL_ROW_CHROME_PX = 12;
+const ARROW_CLICK_MS = 250;
+
+type JsonCellGridApi = {
+  resetRowHeights?: () => void;
+  onRowHeightChanged?: () => void;
+  isDestroyed?: () => boolean;
+};
+
+type JsonCellRowNode = {
+  setRowHeight?: (height: number | null | undefined) => void;
+};
+
+export type JsonCellRendererProps = {
+  value: JsonContainer;
+  rawText?: string;
+  colId: string;
+  autoHeight: boolean;
+  jsonInCell?: boolean;
+  api?: JsonCellGridApi;
+  node?: JsonCellRowNode;
+  eGridCell?: HTMLElement | null;
+};
+
+const Root = styled.div`
+  ${({ theme }) => `
+    display: flex;
+    flex-direction: column;
+    gap: ${theme.sizeUnit / 2}px;
+    width: 100%;
+    min-width: 0;
+    white-space: inherit;
+    word-break: inherit;
+  `}
+`;
+
+const Toolbar = styled.div`
+  ${({ theme }) => `
+    display: flex;
+    align-items: center;
+    gap: ${theme.sizeUnit}px;
+    min-width: 0;
+  `}
+`;
+
+const Preview = styled.span`
+  overflow: hidden;
+  text-overflow: ellipsis;
+  white-space: nowrap;
+  flex: 1;
+  min-width: 0;
+`;
+
+const JsonToggle = styled.button`
+  ${({ theme }) => `
+    display: inline-flex;
+    align-items: center;
+    justify-content: center;
+    width: ${theme.sizeUnit * 4}px;
+    height: ${theme.sizeUnit * 4}px;
+    padding: 0;
+    border: none;
+    background: transparent;
+    color: ${theme.colorTextSecondary};
+    cursor: pointer;
+    flex: none;
+
+    &:hover,
+    &:focus-visible {
+      color: ${theme.colorPrimary};
+    }
+  `}
+`;
+
+const TextToggle = styled.button`
+  display: block;
+  width: 100%;
+  min-width: 0;
+  padding: 0;
+  border: none;
+  background: transparent;
+  color: inherit;
+  font: inherit;
+  text-align: inherit;
+  cursor: pointer;
+  white-space: inherit;
+  word-break: inherit;
+`;
+
+const JsonBlock = styled.div`
+  ${({ theme }) => `
+    display: flex;
+    flex-direction: column;
+    min-width: 0;
+    font-family: ${theme.fontFamilyCode};
+  `}
+`;
+
+const JsonLine = styled.div`
+  display: flex;
+  align-items: flex-start;
+  gap: 4px;
+  min-width: 0;
+`;
+
+const JsonIndent = styled.div`
+  ${({ theme }) => `
+    padding-left: ${theme.sizeUnit * 4}px;
+  `}
+`;
+
+const JsonKey = styled.span`
+  ${({ theme }) => `
+    color: ${theme.colorText};
+    flex: none;
+  `}
+`;
+
+const JsonMuted = styled.span`
+  ${({ theme }) => `
+    color: ${theme.colorTextSecondary};
+  `}
+`;
+
+const StringValue = styled.span`
+  ${({ theme }) => `
+    color: ${theme.colorSuccess};
+  `}
+`;
+
+const NumberValue = styled.span`
+  ${({ theme }) => `
+    color: ${theme.colorPrimary};
+  `}
+`;
+
+const BooleanValue = styled.span`
+  ${({ theme }) => `
+    color: ${theme.colorWarning};
+  `}
+`;
+
+const Tree = styled.div`
+  ${({ theme }) => `
+    font-family: ${theme.fontFamilyCode};
+    font-size: ${theme.fontSizeSM}px;
+    white-space: pre-wrap;
+    word-break: break-word;
+  `}
+`;
+
+// AG Grid selects the row from a listener on the row container. React's
+// delegated click handler runs at the React root, after that listener, so the
+// control stops the native event on the button itself.
+const AG_GRID_STOP_PROPAGATION = '__ag_Grid_Stop_Propagation';
+
+function stopGridPointer(event: Event) {
+  event.stopPropagation();
+  Object.assign(event, { [AG_GRID_STOP_PROPAGATION]: true });
+}
+
+function JsonActionButton({
+  label,
+  expanded,
+  onActivate,
+  plain = false,
+  testId,
+  children,
+}: {
+  label?: string;
+  expanded?: boolean;
+  onActivate: () => void;
+  plain?: boolean;
+  testId?: string;
+  children: ReactNode;
+}) {
+  const ref = useRef<HTMLButtonElement>(null);
+
+  useLayoutEffect(() => {
+    const node = ref.current;
+    if (!node) {
+      return undefined;
+    }
+    const stop = (event: Event) => {
+      stopGridPointer(event);
+    };
+    const onClick = (event: Event) => {
+      stopGridPointer(event);
+      onActivate();
+    };
+    node.addEventListener('pointerdown', stop);
+    node.addEventListener('mousedown', stop);
+    node.addEventListener('click', onClick);
+    node.addEventListener('dblclick', stop);
+    return () => {
+      node.removeEventListener('pointerdown', stop);
+      node.removeEventListener('mousedown', stop);
+      node.removeEventListener('click', onClick);
+      node.removeEventListener('dblclick', stop);
+    };
+  }, [onActivate]);
+
+  const Toggle = plain ? TextToggle : JsonToggle;
+  return (
+    <Toggle
+      ref={ref}
+      type="button"
+      aria-expanded={expanded}
+      aria-label={label}
+      data-json-cell-action
+      data-test={testId}
+    >
+      {children}
+    </Toggle>
+  );
+}
+
+function JsonPrimitive({ value }: { value: unknown }) {
+  if (typeof value === 'string') {
+    return <StringValue>{JSON.stringify(value)}</StringValue>;
+  }
+  if (typeof value === 'number' || typeof value === 'bigint') {
+    return <NumberValue>{String(value)}</NumberValue>;
+  }
+  if (typeof value === 'boolean') {
+    return <BooleanValue>{String(value)}</BooleanValue>;
+  }
+  if (value === null) {
+    return <JsonMuted>null</JsonMuted>;
+  }
+  return <JsonMuted>{String(value)}</JsonMuted>;
+}
+
+function containerEntries(
+  value: JsonContainer,
+): Array<readonly [string, unknown]> {
+  if (Array.isArray(value)) {
+    return value.map((item, index) => [String(index), item] as const);
+  }
+  return Object.entries(value);
+}
+
+function containerSummary(value: JsonContainer): string {
+  if (Array.isArray(value)) {
+    return t('%s items', value.length);
+  }
+  return t('%s keys', Object.keys(value).length);
+}
+
+function JsonNode({
+  value,
+  name,
+  depth,
+  initialOpen = false,
+  onLayoutChange,
+}: {
+  value: unknown;
+  name?: string;
+  depth: number;
+  initialOpen?: boolean;
+  onLayoutChange?: () => void;
+}) {
+  const [open, setOpen] = useState(initialOpen);
+  const isContainer =
+    value !== null &&
+    typeof value === 'object' &&
+    (Array.isArray(value) || Object.getPrototypeOf(value) === 
Object.prototype);
+
+  if (!isContainer || depth >= MAX_JSON_DEPTH) {
+    return (
+      <JsonLine>
+        {name !== undefined && <JsonKey>{name}: </JsonKey>}
+        {isContainer ? (
+          <JsonMuted>…</JsonMuted>
+        ) : (
+          <JsonPrimitive value={value} />
+        )}
+      </JsonLine>
+    );
+  }
+
+  const container = value as JsonContainer;
+  const entries = containerEntries(container);
+  const openBrace = Array.isArray(container) ? '[' : '{';
+  const closeBrace = Array.isArray(container) ? ']' : '}';
+  const label = name !== undefined ? name : 'JSON';
+  const actionLabel = open ? t('Collapse %s', label) : t('Expand %s', label);
+
+  return (
+    <JsonBlock>
+      <JsonLine>
+        <JsonActionButton
+          label={actionLabel}
+          expanded={open}
+          onActivate={() => {
+            setOpen(current => !current);
+            onLayoutChange?.();
+          }}
+        >
+          {open ? (
+            <Icons.CaretDownOutlined iconSize="xs" />
+          ) : (
+            <Icons.CaretRightOutlined iconSize="xs" />
+          )}
+        </JsonActionButton>
+        {name !== undefined && <JsonKey>{name}: </JsonKey>}
+        <span>{openBrace}</span>
+        {!open && (
+          <>
+            <JsonMuted>{containerSummary(container)}</JsonMuted>
+            <span>{closeBrace}</span>
+          </>
+        )}
+      </JsonLine>
+      {open && (
+        <>
+          <JsonIndent>
+            {entries.map(([key, child]) => (
+              <JsonNode
+                key={key}
+                name={key}
+                value={child}
+                depth={depth + 1}
+                onLayoutChange={onLayoutChange}
+              />
+            ))}
+          </JsonIndent>
+          <JsonLine>{closeBrace}</JsonLine>
+        </>
+      )}
+    </JsonBlock>
+  );
+}
+
+export function JsonCellRenderer({
+  value,
+  rawText,
+  colId,
+  autoHeight,
+  jsonInCell = false,
+  api,
+  node,
+  eGridCell,
+}: JsonCellRendererProps) {
+  const [expanded, setExpanded] = useState(false);
+  const [layoutTick, setLayoutTick] = useState(0);
+  const [modalOpen, setModalOpen] = useState(false);
+  const [copied, setCopied] = useState(false);
+  const rootRef = useRef<HTMLDivElement>(null);
+  const arrowClickTimer = useRef<number | undefined>(undefined);
+  const hasAdjustedHeight = useRef(false);
+  const latest = useRef({
+    expanded,
+    autoHeight,
+    api,
+    node,
+    colId,
+  });
+
+  const showTree = jsonInCell && expanded;
+  const preview = jsonCellPreview(value, rawText);
+  const originalText = rawText ?? JSON.stringify(value);
+  const openBrace = Array.isArray(value) ? '[' : '{';
+  const closeBrace = Array.isArray(value) ? ']' : '}';
+  const entries = containerEntries(value);
+
+  const bumpLayout = useCallback(() => {
+    setLayoutTick(tick => tick + 1);
+  }, []);
+
+  useLayoutEffect(() => {
+    latest.current = { expanded: showTree, autoHeight, api, node, colId };
+    const cell = eGridCell ?? null;
+    cell?.classList.toggle('json-cell-expanded', showTree);
+
+    const shouldSync = showTree || hasAdjustedHeight.current;
+    const setRowHeight = node?.setRowHeight;
+    if (shouldSync && !api?.isDestroyed?.()) {
+      hasAdjustedHeight.current = showTree;
+      if (autoHeight) {
+        api?.resetRowHeights?.();
+      } else if (setRowHeight && api?.onRowHeightChanged) {
+        const measured = rootRef.current?.scrollHeight ?? 0;
+        const height =
+          showTree && measured > 0 ? measured + JSON_CELL_ROW_CHROME_PX : 0;
+        syncJsonCellRowHeight(
+          { setRowHeight },

Review Comment:
   `{ setRowHeight }` is a fresh object, and AG Grid's `RowNode.setRowHeight` 
is `this.rowHeight = rowHeight`, so the height lands on this literal instead of 
the row. In fixed-height mode the row never grows on expand, and since the 
WeakMap key is new every call, the collapse branch always early-returns too. 
The cleanup effect at 474 has the same shape.
   
   Could we pass `node` itself (narrowed so `setRowHeight` is defined)? The 
existing `syncJsonCellRowHeight` test reuses one plain object so it can't catch 
this; a fake node that reads `this.rowHeight` would.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to