Improve Diffs Tree View generation
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/103684 fixes a bug with the way the tree view is generated by adding some guard code before assuming values are available.
However, the way the current tree worker code generates the MR tree has potential to be improved.
- Refactor how the file tree is computed to avoid multiple loops
- Do we only use the flattened tree output and - if so - can we avoid recursion entirely?
- Guarantee that filename/path parts cannot accidentally select native JS properties
- We can use a Set to avoid accidentally selecting from the `prototype`
- Fix this browser warning that doesn't seem possible:
- <img src="/uploads/7cca0927656a00ffb5df37636bbd50e6/image.png" width="500px" title="Duplicate keys detected: 'constructor'. This may cause an update error." alt="Duplicate keys detected: 'constructor'. This may cause an update error." />
- It's unclear how this is possible (since there's only one entry named `constructor`), but the fact is that if we use a Set, we can't possibly have multiple entries, and this may expose a Vue defect.
- Consider moving the tree worker out of the worker entirely if we don't need multiple passes or deep recursion
- If we're only generating a single, flat Set, the multi-threaded worker may be unnecessary complexity.
issue