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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UX: Show loading spinner while loading dependencies for ace-editor #26099
Conversation
await waitUntil(() => { | ||
return document.querySelectorAll(".ace_line")[0]; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏌️
await waitUntil(() => { | |
return document.querySelectorAll(".ace_line")[0]; | |
}); | |
await waitUntil(() => document.querySelector(".ace_line")); |
const indexOf = document | ||
.querySelectorAll(".ace_line")[0] | ||
.innerHTML.indexOf("["); | ||
|
||
assert.ok(indexOf >= 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const indexOf = document | |
.querySelectorAll(".ace_line")[0] | |
.innerHTML.indexOf("["); | |
assert.ok(indexOf >= 0); | |
assert.dom(".ace_line").hasText("["); |
@@ -166,14 +178,17 @@ export default class AceEditor extends Component { | |||
} | |||
|
|||
@bind | |||
setAceTheme() { | |||
aceTheme() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we turn it into a getter?
{{loading-spinner size="small"}} | ||
{{/if}} | ||
|
||
<div class="ace hidden">{{this.content}}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not render rather than setting the hidden
class?
{{#if this.isLoading}} | |
{{loading-spinner size="small"}} | |
{{/if}} | |
<div class="ace hidden">{{this.content}}</div> | |
{{#if this.isLoading}} | |
{{loading-spinner size="small"}} | |
{{else}} | |
<div class="ace">{{this.content}}</div> | |
{{/if}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out I can. Initially, I was hiding it because the theme file took time to load and I wanted to avoid the flash. Now that I am loading the theme file upfront, I don't need to hide the div anymore.
window.ace.require(["ace/ace"], (loadedAce) => { | ||
loadedAce.config.set("loadWorkerFromBlob", false); | ||
loadedAce.config.set("workerPath", getURL("/javascripts/ace")); // Do not use CDN for workers | ||
loadScript(`/javascripts/ace/theme-${this.aceTheme()}.js`).then(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't have to load the theme separately before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup it was loaded on demand previously which resulted in the "flash". You can see it clearly in the before screenshot I posted. The solution stated in ajaxorg/ace#3286 is to load the theme file first.
663d819
to
437f3f4
Compare
Why this change? On a slow network, using the `AceEditor` component will result in a blob of text being shown first before being swapped out with the `ace.js` editor after it has completed loading. There is also a problem when setting the theme for the editor which would result in a "flash" as reported in ajaxorg/ace#3286. To avoid this, we need to load the theme js file before displaying the editor. What does this change do? 1. Adds a loading spinner and set the `div.ace` with a `.hidden` class. 2. Once all the relevant scripts and initialization is done, we will then remove the loading spinner and remove `div.ace`.
437f3f4
to
fb7ef84
Compare
Thank you for reviewing @OsamaSayegh and @CvX 👍 |
Why this change?
On a slow network, using the
AceEditor
component will result in a blobof text being shown first before being swapped out with the
ace.js
editor after it has completed loading.
There is also a problem when setting the theme for the editor which
would result in a "flash" as reported in
ajaxorg/ace#3286. To avoid this, we need to
load the theme js file before displaying the editor.
What does this change do?
div.ace
with a.hidden
class.then remove the loading spinner and remove
div.ace
.Reviewer notes
There are no tests here but I discovered this problem when trying to write a system tests and interacting with the ace editor. Because of the previous flashing behaviour, any interactions with the ace editor is unreliable and leads to flaky system tests.
Recording
Before
After