Fix crash when shortcuts chunk fails to load
What does this MR do and why?
Fixes a Sentry-reported crash: TypeError: Cannot read properties of undefined (reading 'addExtension') in behaviors/shortcuts/index.js.
When the shortcutsBundle webpack chunk fails to load (network error, chunk hash mismatch after a deploy, etc.), the .catch(() => {}) on the dynamic import silently resolved shortcutsPromise with undefined. Any subsequent call to addShortcutsExtension then crashed on shortcuts.addExtension(...), and the user lost all keyboard shortcut functionality on that page.
The catch handler now returns a no-op stub ({ addExtension: () => {}, extensions: new Map() }) so callers never receive undefined. This keeps the silent-failure behaviour (shortcuts are optional) while preventing the downstream crash. The extensions: new Map() also keeps resetShortcutsForTests working in test environments.
A regression spec is added that forces the dynamic import to reject and asserts addShortcutsExtension resolves without throwing.
References
Screenshots or screen recordings
Not applicable — no UI change; this prevents a JavaScript crash.
How to set up and validate locally
- Run the new spec:
node_modules/.bin/jest spec/frontend/behaviors/shortcuts/index_spec.js - Confirm the "when the shortcuts bundle fails to load" test passes (it fails on
master). - Run the existing shortcut specs to confirm no regression:
node_modules/.bin/jest spec/frontend/behaviors/shortcuts/ spec/frontend/repository/components/header_area/blob_controls_spec.js
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.