ydb-embedded-ui 4.31.1 → 4.31.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -76,7 +76,7 @@ export const VirtualTable = <T,>({
76
76
 
77
77
  const [error, setError] = useState<IResponseError>();
78
78
 
79
- const [pendingRequests, setPendingRequests] = useState<Record<string, NodeJS.Timeout>>({});
79
+ const pendingRequests = useRef<Record<string, ReturnType<typeof setTimeout>>>({});
80
80
 
81
81
  const fetchChunkData = useCallback(
82
82
  async (id: string) => {
@@ -105,10 +105,13 @@ export const VirtualTable = <T,>({
105
105
  }
106
106
  }, DEFAULT_REQUEST_TIMEOUT);
107
107
 
108
- setPendingRequests((reqs) => {
109
- reqs[id] = timer;
110
- return reqs;
111
- });
108
+ // Chunk data load could be triggered by different events
109
+ // Cancel previous chunk request, while it is pending (instead of concurrentId)
110
+ if (pendingRequests.current[id]) {
111
+ const oldTimer = pendingRequests.current[id];
112
+ window.clearTimeout(oldTimer);
113
+ }
114
+ pendingRequests.current[id] = timer;
112
115
  },
113
116
  [fetchData, limit, sortParams],
114
117
  );
@@ -117,20 +120,27 @@ export const VirtualTable = <T,>({
117
120
  dispatch(initChunk(id));
118
121
  }, []);
119
122
 
120
- const onLeave = useCallback<OnLeave>(
121
- (id) => {
122
- dispatch(removeChunk(id));
123
+ const onLeave = useCallback<OnLeave>((id) => {
124
+ dispatch(removeChunk(id));
125
+
126
+ // If there is a pending request for the removed chunk, cancel it
127
+ // It made to prevent excessive requests on fast scroll
128
+ if (pendingRequests.current[id]) {
129
+ const timer = pendingRequests.current[id];
130
+ window.clearTimeout(timer);
131
+ delete pendingRequests.current[id];
132
+ }
133
+ }, []);
123
134
 
124
- // If there is a pending request for the removed chunk, cancel it
125
- // It made to prevent excessive requests on fast scroll
126
- if (pendingRequests[id]) {
127
- const timer = pendingRequests[id];
135
+ // Cancel all pending requests on component unmount
136
+ useEffect(() => {
137
+ return () => {
138
+ Object.values(pendingRequests.current).forEach((timer) => {
128
139
  window.clearTimeout(timer);
129
- delete pendingRequests[id];
130
- }
131
- },
132
- [pendingRequests],
133
- );
140
+ });
141
+ pendingRequests.current = {};
142
+ };
143
+ }, []);
134
144
 
135
145
  // Load chunks if they become active
136
146
  // This mecanism helps to set chunk active state from different sources, but load data only once
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ydb-embedded-ui",
3
- "version": "4.31.1",
3
+ "version": "4.31.2",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -53,9 +53,9 @@
53
53
  "scripts": {
54
54
  "start": "react-app-rewired start",
55
55
  "dev": "DISABLE_ESLINT_PLUGIN=true TSC_COMPILE_ON_ERROR=true REACT_APP_BACKEND=http://localhost:8765 npm start",
56
- "build": "DISABLE_ESLINT_PLUGIN=true react-app-rewired build",
56
+ "build": "rm -rf build && DISABLE_ESLINT_PLUGIN=true react-app-rewired build",
57
57
  "//build:embedded": "echo 'PUBLIC_URL is a setting for create-react-app. Embedded version is built and hosted as is on ydb servers, with no way of knowing the final URL pattern. PUBLIC_URL=. keeps paths to all static relative, allowing servers to handle them as needed'",
58
- "build:embedded": "rm -rf build && PUBLIC_URL=. REACT_APP_BACKEND=http://localhost:8765 npm run build",
58
+ "build:embedded": "GENERATE_SOURCEMAP=false PUBLIC_URL=. REACT_APP_BACKEND=http://localhost:8765 npm run build",
59
59
  "lint:styles": "stylelint 'src/**/*.scss'",
60
60
  "unimported": "npx unimported --no-cache",
61
61
  "package": "rm -rf dist && copyfiles -u 1 'src/**/*' dist",