Skip to content

Commit 7d3c4c3

Browse files
authored
Fix rerun button of Actions (#22798)
When clicking the return button, the page should be refreshed. However, the browser may cancel the previous fetch request, and it fails to rerun the job. It's easier to reproduce the bug in Safari or Firefox than Chrome for some reason. <img width="384" alt="image" src="https://user-images.githubusercontent.com/9418365/217142792-a783f9a1-7089-44db-b7d8-46c46c72d284.png"> <img width="752" alt="image" src="https://user-images.githubusercontent.com/9418365/217132406-b8381b63-b323-474e-935b-2596b1b5c046.png">
1 parent e8186f1 commit 7d3c4c3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

web_src/js/components/RepoActionView.vue

+9-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<SvgIcon name="octicon-meter" class="ui text yellow" class-name="job-status-rotate" v-else-if="job.status === 'running'"/>
2121
<SvgIcon name="octicon-x-circle-fill" class="red" v-else/>
2222
{{ job.name }}
23-
<button class="job-brief-rerun" @click="rerunJob(index)" v-if="job.canRerun">
23+
<!-- TODO: it will be a better idea to move "button" out from "a", and the ".prevent" will not be needed. But it needs some work with CSS -->
24+
<button class="job-brief-rerun" @click.prevent="rerunJob(index)" v-if="job.canRerun">
2425
<SvgIcon name="octicon-sync" class="ui text black"/>
2526
</button>
2627
</a>
@@ -162,12 +163,14 @@ const sfc = {
162163
}
163164
},
164165
// rerun a job
165-
rerunJob(idx) {
166-
this.fetch(`${this.run.link}/jobs/${idx}/rerun`);
166+
async rerunJob(idx) {
167+
const jobLink = `${this.run.link}/jobs/${idx}`;
168+
await this.fetchPost(`${jobLink}/rerun`);
169+
window.location.href = jobLink;
167170
},
168171
// cancel a run
169172
cancelRun() {
170-
this.fetch(`${this.run.link}/cancel`);
173+
this.fetchPost(`${this.run.link}/cancel`);
171174
},
172175
173176
createLogLine(line) {
@@ -205,7 +208,7 @@ const sfc = {
205208
// for example: make cursor=null means the first time to fetch logs, cursor=eof means no more logs, etc
206209
return {step: idx, cursor: it.cursor, expanded: it.expanded};
207210
});
208-
const resp = await this.fetch(
211+
const resp = await this.fetchPost(
209212
`${this.actionsURL}/runs/${this.runIndex}/jobs/${this.jobIndex}`,
210213
JSON.stringify({logCursors}),
211214
);
@@ -245,7 +248,7 @@ const sfc = {
245248
}
246249
},
247250
248-
fetch(url, body) {
251+
fetchPost(url, body) {
249252
return fetch(url, {
250253
method: 'POST',
251254
headers: {

0 commit comments

Comments
 (0)