Skip to content

Commit a9a69e4

Browse files
committed
Short circuit redirects so that morphing and load states don't happen before the redirect.
1 parent 41d2567 commit a9a69e4

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

django_unicorn/static/unicorn/js/messageSender.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export function send(component, callback) {
109109
);
110110
} else {
111111
component.window.location.href = responseJson.redirect.url;
112+
113+
// Prevent anything else from happening if there is a url redirect
114+
return;
112115
}
113116
} else if (responseJson.redirect.hash) {
114117
component.window.location.hash = responseJson.redirect.hash;

tests/js/component/messageSender.test.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fetchMock from "fetch-mock";
33
import { getComponent } from "../utils.js";
44
import { send } from "../../../django_unicorn/static/unicorn/js/messageSender.js";
55

6-
test.cb("call_method redirect", (t) => {
6+
test("call_method redirect", (t) => {
77
const html = `
88
<input type="hidden" name="csrfmiddlewaretoken" value="asdf">
99
<div unicorn:id="5jypjiyb" unicorn:name="text-inputs" unicorn:checksum="GXzew3Km">
@@ -38,7 +38,6 @@ test.cb("call_method redirect", (t) => {
3838
t.true(err === null);
3939
t.is(component.window.location.href, "http://www.google.com");
4040
fetchMock.reset();
41-
t.end();
4241
});
4342
});
4443

@@ -127,7 +126,7 @@ test.cb("call_method hash", (t) => {
127126
});
128127
});
129128

130-
test.cb("call_method forceModelUpdate is true", (t) => {
129+
test("call_method forceModelUpdate is true", (t) => {
131130
const html = `
132131
<input type="hidden" name="csrfmiddlewaretoken" value="asdf">
133132
<div unicorn:id="5jypjiyb" unicorn:name="text-inputs" unicorn:checksum="GXzew3Km">
@@ -162,11 +161,10 @@ test.cb("call_method forceModelUpdate is true", (t) => {
162161
t.true(err === null);
163162
t.true(forceModelUpdates);
164163
fetchMock.reset();
165-
t.end();
166164
});
167165
});
168166

169-
test.cb("call_method partial.id", (t) => {
167+
test("call_method partial.id", (t) => {
170168
// Annoyingly it appears that $('[unicorn\\:key='something']) doesn't
171169
// seem to work in JSDom, so this just tests targeting by id
172170
const html = `
@@ -214,11 +212,10 @@ test.cb("call_method partial.id", (t) => {
214212
t.is(morphdomMergers.length, 1);
215213
t.is(morphdomMergers[0], "<span id='clicker-id'>id partial!</span>");
216214
fetchMock.reset();
217-
t.end();
218215
});
219216
});
220217

221-
test.cb("call_method partial target", (t) => {
218+
test("call_method partial target", (t) => {
222219
// Annoyingly it appears that $('[unicorn\\:key='something']) doesn't
223220
// seem to work in JSDom, so this just tests targeting by id
224221
const html = `
@@ -265,6 +262,5 @@ test.cb("call_method partial target", (t) => {
265262
t.is(morphdomMergers.length, 1);
266263
t.is(morphdomMergers[0], "<span id='clicker-id'>id partial!</span>");
267264
fetchMock.reset();
268-
t.end();
269265
});
270266
});

0 commit comments

Comments
 (0)