Resolve "WebIDE displays blank file incorrectly"
What does this MR do?
This MR is preventing the Web IDE editor from being initialized before raw file data is fetched. Otherwise, the user would be presented with an empty editor instead.
The MR is done in four commits, first is only refactoring, second implements the fix, third is improving how we toggle the file.loading
flag and fourth is adding a functional test against regression. It's possibly easier to review them separately.
TL;DR You can only read Opening two files quickly one after the other for the problem description and Chosen solution for solution explanation.
I'm sorry for the information overload below, it's been a week worth of investigation.
Problem in detail
The problem is that the editor initialization can be triggered when the last opened file is still being fetched. This results in creating an empty model and when the file.raw
data comes in, we don't update the model which is cached.
This was happening in two scenarios:
Opening two files quickly one after the other
- Set file
A
as active (i.e. open it by clicking at the tree item) - The editor starts fetching file
A
- Set file
B
as active - The editor starts fetching file
B
- File
A
is fetched and we initialize the Editor- the problem is that
editor.file
property is already set to fileB
, so we initialize editor for fileB
before we have theB
content
- the problem is that
- File
B
is fetched, but we don't update the editor model with the content
viewMode
whilst the file is still loading
Switching Very similar to the previous scenario, but this time the Editor initialization is triggered by the watcher for viewer
property
Possible solutions
- Hacks
- use the opposite condition from fetch data
- When call
fetchData
, we cancel immediately if the following condition istrue
file.raw || (file.tempFile && !file.prevPath && !fileDeletedAndReadded)
- This condition signals that fetching is not necessary
- We could invert this condition and use it to cancel the editor setup (i.e. if fetching is necessary, don't set up the editor)
- When call
- update the model after data comes in
- We could incorrectly initialize the empty model but listen of changes in
file.raw
and update the model with incoming data - This could lead to problems like the user starting to make some changes to the incorrectly empty file and those changes being overridden
- We could incorrectly initialize the empty model but listen of changes in
- use the opposite condition from fetch data
- Good enough
- See chosen solution
- Best
- Move the file content fetching (
fetchData
) fromrepo_editor.vue
to our actions. - That would remove the strange discrepancy when dispatching
getData()
action changes the state as a side-effect andrepo_editor.setup
relies on that change rather implicitly
- Move the file content fetching (
Chosen solution
The "good enough" solution is IMO to make sure we don't set up the editor when the file is still loading. The fix contains two changes:
- aborting editor setup if the file is still loading
- making sure that when
getRawFileData
action is in progress, the file hasfile.loading: true
property
Drawbacks of the solution
The current implemententaion first fetches file data and then raw file data:
loading:true
- call
getFileData()
loading: false
loading: true
- call
getRawFileData()
loading:false
That means there is a very unlikely scenario of the editor being opened in between these two fetches and the original bug still manifesting itself. Ideally, we would do the fetch atomically, having the loading: true
attribute continually throughout both fetches. That's not easy to implement because the getFileData()
action is used separately as well.
Another drawback is that we implicitly rely on the fact that when the file finishes loading, we are going to initialize the editor.
this.fetchFileData()
.then(() => {
this.createEditorInstance();
})
In other words, if the editor.file.loading
is true, but createEditorInstance()
is called, we just assume that we can discard this initialization because createEditorInstance()
will be called again when the file is done loading.
Screenshots
Before | After | |
---|---|---|
Changing view mode | ||
Opening another file |
Does this MR meet the acceptance criteria?
Conformity
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
Doesn't apply.
Closes #214824 (closed)