Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add cleanup callbacks to someuseEffect calls#13444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aslilac merged 3 commits intomainfromeffect-cleanup
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletionssite/src/contexts/useProxyLatency.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -225,6 +225,10 @@ export const useProxyLatency = (
// Local storage cleanup
garbageCollectStoredLatencies(proxies, maxStoredLatencies);
});

return () => {
observer.disconnect();
};
}, [proxies, latestFetchRequest, maxStoredLatencies]);

return {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -245,20 +245,32 @@ const useFileTree = (templateVersion: TemplateVersion | undefined) => {
fileTree: undefined,
tarFile: undefined,
});

useEffect(() => {
let stale = false;
const initializeFileTree = async (file: ArrayBuffer) => {
const tarFile = new TarReader();
await tarFile.readFile(file);
const fileTree = await createTemplateVersionFileTree(tarFile);
setState({ fileTree, tarFile });
try {
await tarFile.readFile(file);
// Ignore stale updates if this effect has been cancelled.
if (stale) {
return;
}
const fileTree = createTemplateVersionFileTree(tarFile);
setState({ fileTree, tarFile });
} catch (error) {
console.error(error);
displayError("Error on initializing the editor");
}
};

if (fileQuery.data) {
initializeFileTree(fileQuery.data).catch((reason) => {
console.error(reason);
displayError("Error on initializing the editor");
});
void initializeFileTree(fileQuery.data);
}

return () => {
stale = true;
};
}, [fileQuery.data]);

return state;
Expand Down
5 changes: 4 additions & 1 deletionsite/src/pages/WorkspacePage/WorkspaceBuildProgress.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,7 +97,10 @@ export const WorkspaceBuildProgress: FC<WorkspaceBuildProgressProps> = ({
setProgressValue(est);
setProgressText(text);
};
setTimeout(updateProgress, 5);
const updateTimer = requestAnimationFrame(updateProgress);
return () => {
cancelAnimationFrame(updateTimer);
};
}, [progressValue, job, transitionStats]);

// HACK: the codersdk type generator doesn't support null values, but this
Expand Down
4 changes: 2 additions & 2 deletionssite/src/utils/templateVersion.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,9 +23,9 @@ export const getTemplateVersionFiles = async (
return files;
};

export const createTemplateVersionFileTree =async(
export const createTemplateVersionFileTree = (
tarReader: TarReader,
):Promise<FileTree> => {
): FileTree => {
let fileTree: FileTree = {};
for (const file of tarReader.fileInfo) {
fileTree = set(
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp