1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Remove setTimeout() hacks for Javelin behavior initialization

Summary:
  - Prioritize higher-priority behaviors on the server.
  - Remove setTimeout() hacks.

Test Plan: Loaded Differential, didn't get CSRF races for comment previews.

Reviewers: aran, jg, cpojer

Reviewed By: jg

CC: btrahan, jungejason, aran, epriestley, jg

Differential Revision: 1183
This commit is contained in:
epriestley 2011-12-07 13:49:56 -08:00
parent 4fc37c3dde
commit c16c920f94
4 changed files with 28 additions and 5 deletions

View file

@ -146,9 +146,31 @@ final class CelerityStaticResourceResponse {
$onload = array();
if ($this->behaviors) {
$behavior = json_encode($this->behaviors);
$onload[] = 'JX.initBehaviors('.$behavior.')';
$behaviors = $this->behaviors;
$this->behaviors = array();
$higher_priority_names = array(
'refresh-csrf',
);
$higher_priority_behaviors = array_select_keys(
$behaviors,
$higher_priority_names);
foreach ($higher_priority_names as $name) {
unset($behaviors[$name]);
}
$behavior_groups = array(
$higher_priority_behaviors,
$behaviors);
foreach ($behavior_groups as $group) {
if (!$group) {
continue;
}
$onload[] = 'JX.initBehaviors('.json_encode($group).')';
}
}
if ($onload) {

View file

@ -9,6 +9,7 @@
phutil_require_module('phabricator', 'infrastructure/celerity/map');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('CelerityStaticResourceResponse.php');

View file

@ -30,7 +30,7 @@ JX.behavior('differential-feedback-preview', function(config) {
JX.DOM.listen(content, 'keydown', null, trigger);
JX.DOM.listen(action, 'change', null, trigger);
setTimeout(function() { request.start(); }, 0);
request.start();
function refreshInlinePreview() {
@ -46,5 +46,5 @@ JX.behavior('differential-feedback-preview', function(config) {
null,
refreshInlinePreview);
setTimeout(refreshInlinePreview, 0);
refreshInlinePreview();
});

View file

@ -46,5 +46,5 @@ JX.behavior('maniphest-transaction-preview', function(config) {
JX.DOM.listen(comments, 'keydown', null, trigger);
JX.DOM.listen(action, 'change', null, trigger);
setTimeout(function() { request.start(); }, 0);
request.start();
});