Fix dynamic script loading with Vite
What does this MR do and why?
This MR fixes the wrong JS execution order when using Vite in development mode or with running feature specs.
The bug was introduced by another fix: Address Vite networking issue (!154546 - merged), which introduced a different method of inserting our JS entrypoints to the page. Before, the code was coming from the Rails HTML, after the fix the code was generated client-side, which broke the defer
behaviour: scripts no longer were waiting for previous scripts to finish execution. This is an oversight on the spec and browser implementation side that we can't affect.
This is how the bug was discovered (internal link), notice that the page entrypoint is loaded before super_sidebar
, which should be loaded first:
In order to fix this we'll programatically attach error
event listeners without creating script tags manually.
This MR should reduce e2e pipeline flakiness and lower it to 0%.
How to set up and validate locally
- Go to https://gdk.test:3443/-/user_settings/personal_access_tokens
- Refresh the page multiple times
- No
Property or method "s__" is not defined on the instance
error should appear in the console