dsuhinin commented on code in PR #70536: URL: https://github.com/apache/airflow/pull/70536#discussion_r4026827359
########## airflow-core/src/airflow/ui/src/layouts/Details/Grid/useGridScrollRestoration.ts: ########## @@ -0,0 +1,103 @@ +/*! + * 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 { useEffect, useLayoutEffect, useRef } from "react"; +import { useLocation } from "react-router-dom"; + +/** + * Grid vertical scroll offset per ``dagId``, kept at module scope so it survives the + * remount that happens when navigating between the sibling ``<Dag>`` / ``<Run>`` / + * ``<Task>`` / ``<TaskInstance>`` routes — each mounts its own ``Grid``, which would + * otherwise start at ``scrollTop = 0``. + */ +const gridScrollOffsetByDagId = new Map<string, number>(); + +// Matches a specific Dag (`/dags/<id>...`) but not the `/dags` list. +const DAG_DETAILS_PATH = /^\/dags\/(?<dagId>[^/]+)/u; + +export const extractDagIdFromPath = (pathname: string): string | undefined => + DAG_DETAILS_PATH.exec(pathname)?.groups?.dagId; Review Comment: hey @bbovenzi ! Can you please take a look into the new approach -> https://github.com/apache/airflow/pull/73123. We don't store a raw pixel top-offset as the source of truth. On the remount that opening a task triggers, we restore the last scrollTop only to avoid the Grid jumping; and because that remount never changes the structure, the offset still lines up. If the structure does change (new version, or groups expanded/collapsed), the restored offset no longer matches, so we fall back to locating the selected task by id in the flattened rows and, since rows are fixed-height, use the index to center it — no reliance on the stored pixels. So the failure mode you flagged is handled by the index path. -- 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]
