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


##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx:
##########
@@ -144,12 +144,12 @@ const publishDataMask = debounce(
       // it when necessary. We strip any prefix so that history.replace adds 
it back and doesn't
       // double it up.
       const appRoot = applicationRoot();
-      let replacement_pathname = window.location.pathname;
-      if (appRoot !== '/' && replacement_pathname.startsWith(appRoot)) {
-        replacement_pathname = replacement_pathname.substring(appRoot.length);
+      let replacementPathname = window.location.pathname;
+      if (appRoot !== '/' && replacementPathname.startsWith(appRoot)) {
+        replacementPathname = replacementPathname.substring(appRoot.length);
       }
-      history.location.pathname = replacement_pathname;
       history.replace({
+        pathname: replacementPathname,
         search: newParams.toString(),

Review Comment:
   **Suggestion:** When `applicationRoot()` returns a path with a trailing 
slash (for example `/superset/`), stripping it from `window.location.pathname` 
can produce a pathname without a leading `/` (e.g. `dashboard/1`), which React 
Router may interpret as a relative path and generate incorrect URLs when 
calling `history.replace`. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Dashboard URL can become malformed after applying filters.
   - ❌ Users may see 404 when dashboard path is corrupted.
   - ⚠️ Permalink URLs may be generated with incorrect paths.
   ```
   </details>
   
   ```suggestion
         const appRoot = applicationRoot();
         let replacementPathname = window.location.pathname;
         if (appRoot !== '/' && replacementPathname.startsWith(appRoot)) {
           replacementPathname = replacementPathname.substring(appRoot.length);
           if (!replacementPathname.startsWith('/')) {
             replacementPathname = `/${replacementPathname}`;
           }
         }
         history.replace({
           pathname: replacementPathname,
           search: newParams.toString(),
         });
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Configure Superset backend so that `APPLICATION_ROOT` (used by frontend
   `applicationRoot()` in `superset-frontend/src/utils/getBootstrapData.ts`) 
includes a
   trailing slash, for example `/superset/`.
   
   2. Start the web app and open a dashboard at 
`/superset/dashboard/<dashboard_id>` so that
   `FilterBar`
   
(`superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx`)
 is
   rendered.
   
   3. Change any native filter and click **Apply**; this updates 
`dataMaskApplied`, which
   triggers the `useEffect` at lines 382–387 in `FilterBar/index.tsx` that calls
   `publishDataMask(history, dashboardId, updateKey, dataMaskApplied, tabId)`.
   
   4. Inside `publishDataMask` (same file, lines 133–154), when 
`window.location.pathname` is
   `/superset/dashboard/<dashboard_id>` and `applicationRoot()` returns 
`/superset/`, the
   code at lines 146–153 sets `replacementPathname` to 
`dashboard/<dashboard_id>` (no leading
   slash) and calls `history.replace({ pathname: replacementPathname, search:
   newParams.toString() })`; with React Router configured with a basename of 
`/superset/`,
   this can produce a malformed URL like `/supersetdashboard/<dashboard_id>`, 
breaking
   dashboard navigation and permalinks.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx
   **Line:** 146:153
   **Comment:**
        *Logic Error: When `applicationRoot()` returns a path with a trailing 
slash (for example `/superset/`), stripping it from `window.location.pathname` 
can produce a pathname without a leading `/` (e.g. `dashboard/1`), which React 
Router may interpret as a relative path and generate incorrect URLs when 
calling `history.replace`.
   
   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.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37681&comment_hash=6f55d33a6398cc7c26a496cb2b5bfda7e016b7e14e98ce29cf83524c0756f6a4&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37681&comment_hash=6f55d33a6398cc7c26a496cb2b5bfda7e016b7e14e98ce29cf83524c0756f6a4&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