mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-12 13:48:58 +02:00
fix: ignore stale file responses after viewer navigation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"core.min.js": "core.6332b3c288.min.js",
|
||||
"vendor.min.js": "vendor.1020f4867e.min.js",
|
||||
"vendor.min.js": "vendor.1269d561e8.min.js",
|
||||
"mermaid.min.js": "mermaid.f848a72d16.min.js",
|
||||
"all.min.css": "all.99ce8f3e14.min.css"
|
||||
}
|
||||
|
||||
@@ -2577,6 +2577,13 @@ angular
|
||||
"$sce",
|
||||
"$q",
|
||||
function ($scope, $http, $location, $routeParams, $sce, $q) {
|
||||
let contentGeneration = 0;
|
||||
let destroyed = false;
|
||||
$scope.$on("$destroy", () => {
|
||||
destroyed = true;
|
||||
contentGeneration++;
|
||||
if (searchCanceller) searchCanceller.resolve();
|
||||
});
|
||||
$scope.files = [];
|
||||
$scope.isMac = /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent);
|
||||
$scope.fileSearchQuery = "";
|
||||
@@ -2913,6 +2920,7 @@ angular
|
||||
}
|
||||
|
||||
function getContent(path, fileInfo) {
|
||||
const generation = contentGeneration;
|
||||
if (!path) {
|
||||
$scope.type = "error";
|
||||
$scope.content = "no_file_selected";
|
||||
@@ -2938,6 +2946,7 @@ angular
|
||||
)
|
||||
.then(
|
||||
(res) => {
|
||||
if (destroyed || generation !== contentGeneration) return;
|
||||
$scope.type = originalType;
|
||||
$scope.content = res.data;
|
||||
if ($scope.content == "") {
|
||||
@@ -2976,6 +2985,7 @@ angular
|
||||
}, 50);
|
||||
},
|
||||
(err) => {
|
||||
if (destroyed || generation !== contentGeneration) return;
|
||||
$scope.type = "error";
|
||||
$scope.content = "unknown_error";
|
||||
try {
|
||||
@@ -2999,6 +3009,7 @@ angular
|
||||
}
|
||||
|
||||
function updateContent() {
|
||||
contentGeneration++;
|
||||
$scope.content = "";
|
||||
$scope.file = getSelectedFile();
|
||||
let fileVersion = "0";
|
||||
@@ -3172,6 +3183,7 @@ angular
|
||||
}
|
||||
|
||||
function init() {
|
||||
contentGeneration++;
|
||||
$scope.repoId = $routeParams.repoId;
|
||||
$scope.type = "loading";
|
||||
$scope.filePath = $routeParams.path || "";
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -74,4 +74,15 @@ describe("frontend production regressions", function () {
|
||||
h.navigate("file.org"); h.requests.at(-1).resolve({ data: "org source", headers: () => "text/plain" }); await h.flush();
|
||||
expect(untrusted).to.include("onerror"); expect(h.scope.content).to.equal("sanitized");
|
||||
});
|
||||
it("ignores stale successes and failures after selecting another file", async function () {
|
||||
const h = explorer();
|
||||
h.navigate("first.js"); const first = h.requests.at(-1);
|
||||
h.navigate("second.js"); const second = h.requests.at(-1);
|
||||
second.resolve({ data: "SECOND", headers: () => "text/plain" }); await h.flush();
|
||||
first.resolve({ data: "FIRST", headers: () => "text/plain" }); await h.flush();
|
||||
expect(h.scope.content).to.equal("SECOND");
|
||||
h.navigate("third.js"); const third = h.requests.at(-1);
|
||||
h.navigate("fourth.pdf"); third.reject({ status: 500 }); await h.flush();
|
||||
expect(h.scope.type).to.equal("pdf");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user