Skip to content

Fix highlight worker event ordering

Jacques Erasmus requested to merge je-fix-worker-message into master

What does this MR do and why?

Fixes a bug caused by incorrect event order.

Some context:

We use a web worker to handle the task of highlighting source code on the frontend. To improve perceived performance we ask the worker to highlight the first 70 lines immediately while we highlight the entire file in the background.

Example:

  • Task 1: Highlight lines 0-70
  • Task 2: highlight lines 0-500

Sometimes these two events finish in the incorrect order (i.e. Task 1 finishes after Task 2) which results in only the first 70 line being rendered. This is especially visible for smaller files where the highlighting tasks are so fast that it can mess up the order.

To prevent this we can ensure that we only render the content if the content length is larger than the current content length.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Before After
Only lines 0-70 are rendered All lines are rendered
Screenshot_2024-02-19_at_15.07.47 Screenshot_2024-02-19_at_15.08.11

How to set up and validate locally

  1. Open a source code file via the repository files browser
  2. The file should render as expected
Edited by Jacques Erasmus

Merge request reports