codeant-ai-for-open-source[bot] commented on code in PR #42602:
URL: https://github.com/apache/superset/pull/42602#discussion_r3707324067


##########
superset-frontend/packages/superset-core/src/theme/SupersetThemeProvider.test.tsx:
##########
@@ -0,0 +1,205 @@
+/**
+ * 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 { useLayoutEffect, type ReactNode } from 'react';
+import { render, screen, act } from '@testing-library/react';
+import { theme as antdThemeImport } from 'antd';
+import { Theme } from './Theme';
+
+// SupersetThemeProvider stores theme state via React.useState, then
+// registers a listener (in a useEffect, on mount) that calls setThemeState
+// whenever a *later* call to setConfig/toggleDarkMode runs on the same

Review Comment:
   **Suggestion:** The test commentary says provider registration occurs in a 
`useEffect`, but the implementation under test now registers it with 
`useLayoutEffect`. This contradicts the behavior being tested and can mislead 
future maintenance about the effect ordering required for the initial-mount 
race. [comment mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Minor ๐Ÿงน</summary>
   
   ```mdx
   - โš ๏ธ Misleading comment conflicts with the tested effect-ordering contract.
   - โš ๏ธ Runtime provider behavior is unaffected by this documentation mismatch.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=11b4316452624ac189b2630ca21d383b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=11b4316452624ac189b2630ca21d383b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/packages/superset-core/src/theme/SupersetThemeProvider.test.tsx
   **Line:** 24:26
   **Comment:**
        *Comment Mismatch: The test commentary says provider registration 
occurs in a `useEffect`, but the implementation under test now registers it 
with `useLayoutEffect`. This contradicts the behavior being tested and can 
mislead future maintenance about the effect ordering required for the 
initial-mount race.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42602&comment_hash=6447154b5dd36768fe07566378a684cf1cc53427d9d3ca12d6ec55234e75d3fe&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42602&comment_hash=6447154b5dd36768fe07566378a684cf1cc53427d9d3ca12d6ec55234e75d3fe&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset-frontend/packages/superset-core/src/theme/SupersetThemeProvider.test.tsx:
##########
@@ -0,0 +1,205 @@
+/**
+ * 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 { useLayoutEffect, type ReactNode } from 'react';
+import { render, screen, act } from '@testing-library/react';
+import { theme as antdThemeImport } from 'antd';
+import { Theme } from './Theme';
+
+// SupersetThemeProvider stores theme state via React.useState, then
+// registers a listener (in a useEffect, on mount) that calls setThemeState
+// whenever a *later* call to setConfig/toggleDarkMode runs on the same
+// Theme instance. Every provider currently mounted from that instance
+// listens independently, so toggling the instance updates all of them, not
+// just the most recently rendered one. Consumers
+// (docs/src/components/StorybookWrapper.jsx in particular) rely on this:
+// they call toggleDarkMode() from outside, on one or more already-mounted
+// providers sharing a single Theme instance, expecting it to propagate to
+// all of them.
+//
+// The probe below reads the theme via antd's theme.useToken() -- the same
+// context-consumption path every real antd component (Button, Input, ...)
+// uses internally -- rather than reading themeObject.theme directly off the
+// singleton. That distinction matters: React bails out of re-rendering a
+// child whose element reference didn't change (the common "static children
+// prop" case, true here since <Probe /> is passed once and never
+// recreated), UNLESS that child consumes a React Context whose value
+// changed, which bypasses the bail-out. A probe reading the plain object
+// directly would misleadingly appear "not updated" even though every real
+// themed component downstream re-renders correctly.
+function makeProbe() {
+  let renderCount = 0;
+  let lastColorBgBase: string | undefined;
+  function Probe() {
+    const { token } = antdThemeImport.useToken();
+    renderCount += 1;
+    lastColorBgBase = token.colorBgBase;
+    return <div data-test="probe" />;

Review Comment:
   **Suggestion:** The probe sets `data-test`, but `getByTestId` only searches 
for `data-testid`, so the first test throws before exercising theme 
propagation. Rename the attribute to `data-testid` or query the attribute that 
is actually rendered. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major โš ๏ธ</summary>
   
   ```mdx
   - โŒ Superset core test suite fails deterministically.
   - โš ๏ธ Theme propagation regression test never reaches its toggle assertions.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0a3c45e60752463d872a360dc11daa0f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0a3c45e60752463d872a360dc11daa0f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/packages/superset-core/src/theme/SupersetThemeProvider.test.tsx
   **Line:** 52:52
   **Comment:**
        *Api Mismatch: The probe sets `data-test`, but `getByTestId` only 
searches for `data-testid`, so the first test throws before exercising theme 
propagation. Rename the attribute to `data-testid` or query the attribute that 
is actually rendered.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42602&comment_hash=f924ac6bb77f54e2a98c1d8e1124c8a0b3698d871432b8cdcd0f71ec91ea32f5&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42602&comment_hash=f924ac6bb77f54e2a98c1d8e1124c8a0b3698d871432b8cdcd0f71ec91ea32f5&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset-frontend/packages/superset-core/src/theme/Theme.tsx:
##########
@@ -185,6 +185,24 @@ export class Theme {
       newConfig.algorithm = newAlgorithm;
     }
 
+    // Skip the update (and the notifyProviders fan-out it triggers) if the
+    // theme is already in the requested mode. Docs pages mount one
+    // dark-mode-sync bridge per live component demo (see
+    // docs/src/components/StorybookWrapper.jsx's ThemeSync), so a single
+    // toggle event calls this once per demo on the page. Without this
+    // check, every one of those calls would recompute the theme and
+    // notify every mounted provider, turning a single real toggle into
+    // O(n^2) provider notifications across n demos.
+    const currentAlgorithm = this.antdConfig.algorithm;
+    const algorithmUnchanged = Array.isArray(newConfig.algorithm)
+      ? Array.isArray(currentAlgorithm) &&
+        newConfig.algorithm.length === currentAlgorithm.length &&
+        newConfig.algorithm.every((alg, i) => alg === currentAlgorithm[i])
+      : newConfig.algorithm === currentAlgorithm;
+    if (algorithmUnchanged) {
+      return;

Review Comment:
   **Suggestion:** The no-op check compares algorithm arrays by order, but 
`toggleDarkMode` constructs a new array with the requested mode algorithm 
first. For an existing configuration such as `[compactAlgorithm, 
darkAlgorithm]`, requesting dark mode produces `[darkAlgorithm, 
compactAlgorithm]`, so this condition is false and `setConfig` is called even 
though the requested mode is already active. This directly causes the added 
no-op test to fail; compare the mode algorithm independently of the ordering of 
other algorithms. [incorrect condition logic]
   
   <details>
   <summary><b>Severity Level:</b> Major โš ๏ธ</summary>
   
   ```mdx
   - โŒ Theme no-op regression test fails for compact dark configurations.
   - โš ๏ธ Repeated dark-mode sync recomputes and reorders algorithms 
unnecessarily.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0291a311e59b48f3bebe346a7e9212b1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0291a311e59b48f3bebe346a7e9212b1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/packages/superset-core/src/theme/Theme.tsx
   **Line:** 196:203
   **Comment:**
        *Incorrect Condition Logic: The no-op check compares algorithm arrays 
by order, but `toggleDarkMode` constructs a new array with the requested mode 
algorithm first. For an existing configuration such as `[compactAlgorithm, 
darkAlgorithm]`, requesting dark mode produces `[darkAlgorithm, 
compactAlgorithm]`, so this condition is false and `setConfig` is called even 
though the requested mode is already active. This directly causes the added 
no-op test to fail; compare the mode algorithm independently of the ordering of 
other algorithms.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42602&comment_hash=f3ee38d1ef4a8b25f0197ca7bdefb0ee849f119a7609c1af0233192e92764196&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42602&comment_hash=f3ee38d1ef4a8b25f0197ca7bdefb0ee849f119a7609c1af0233192e92764196&reaction=dislike'>๐Ÿ‘Ž</a>



-- 
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