Commit Graph

37 Commits

Author SHA1 Message Date
Matt Godbolt
23fad10939 Unit testing the frontend (#7829)
This adds some unit tests for the front end.

- configures "frontend tests" as a unit tests in `static/tests`,
removing the old cypress-requiring "unit" tests
- hack enough of a DOM  to get things working
- port motd and id tests
- *adds* a golden layout checks  (see #7807)
- Updates READMEs etc

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-06-19 08:46:57 -05:00
Matt Godbolt
4ef43a86e5 Improve GoldenLayout type safety (Phase 1) (#7801)
## Summary

This PR significantly improves type safety for GoldenLayout
configurations, continuing work from issue #4490 "The War of The Types".
This is an **incremental improvement** that establishes a solid
foundation for future work.

##  What We've Accomplished

### Core Type Infrastructure
- **Created comprehensive type system** in
`static/components.interfaces.ts`
- **Added `ComponentConfig<K>`** with proper generic constraints for
type-safe component configurations
- **Added `GoldenLayoutConfig`** to replace unsafe `any[]` content with
strongly-typed `ItemConfig[]`
- **Created `ComponentStateMap`** mapping component names to their
expected state types
- **Added proper TypeScript component name constants** with `as const`
for literal type inference

### Component Configuration Type Safety  
- **All component factory functions** now return strongly-typed
configurations
- **Clean type syntax**: `ComponentConfig<'compiler'>` using the
exported constants
- **Eliminated unsafe casts** in component creation and drag source
setup
- **Fixed hub method signatures** that incorrectly expected
`ContentItem` instead of `ItemConfig`

### Bug Fixes and Code Quality
- **Fixed Jeremy's TODO**: Improved `fixBugsInConfig` function typing 
- **Discovered and fixed hub type bug**:
`addAtRoot`/`addInEditorStackIfPossible` now accept correct types
- **Removed legacy conversion functions** that were no longer needed
- **Replaced verbose TODO comments** with GitHub issue references for
better organization

### Documentation and Planning
- **Created GitHub issues**
[#7807](https://github.com/compiler-explorer/compiler-explorer/issues/7807)
and
[#7808](https://github.com/compiler-explorer/compiler-explorer/issues/7808)
for remaining work
- **Documented type safety approach** with clear explanations of design
decisions
- **Added comprehensive implementation notes** for future contributors

## 🚧 What's Next (GitHub Issues)

- **Issue #7807**: [Type-safe
serialization/deserialization](https://github.com/compiler-explorer/compiler-explorer/issues/7807)
  - localStorage persistence and URL sharing 
  - SerializedLayoutState implementation
  - Version migration support

- **Issue #7808**: [Configuration validation and remaining type
gaps](https://github.com/compiler-explorer/compiler-explorer/issues/7808)
  - Enable `fromGoldenLayoutConfig` validation
  - Fix upstream GoldenLayout TypeScript definitions
  - State type normalization (addresses #4490)

## 📊 Impact

### Type Safety Improvements
- **No more `any` casts** in component configuration creation
- **Compile-time validation** of component names and state types
- **Better IDE support** with autocomplete and type checking
- **Runtime safety** through proper TypeScript interfaces

### Code Quality
- **~100 lines of verbose TODO comments** replaced with concise GitHub
issue references
- **Technical debt reduction** through elimination of unsafe casting
patterns
- **Improved maintainability** with centralized type definitions
- **Better error messages** when component configurations are incorrect

### Files Modified
- `static/components.interfaces.ts` - Core type definitions
- `static/components.ts` - Component factory functions and utilities  
- `static/main.ts` - Layout initialization and configuration handling
- `static/hub.ts` - Fixed method signatures
- `static/panes/*.ts` - Updated component creation patterns

##  Testing & Validation

- **All existing tests pass** - no runtime regressions
- **TypeScript compilation succeeds** with strict type checking
- **Linting passes** with no new warnings
- **Pre-commit hooks validated** all changes
- **Manual testing confirmed** layout functionality works correctly

## 🎯 Ready to Merge

This PR represents a **significant incremental improvement** that:
-  **Provides immediate value** through better type safety
-  **Maintains full backward compatibility** 
-  **Establishes solid foundation** for future improvements
-  **Centralizes remaining work** in well-documented GitHub issues
-  **Ready for production use** with no runtime changes

The remaining work is clearly tracked in the linked GitHub issues and
can be tackled incrementally in future PRs.

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-06-18 09:22:24 -05:00
Matt Godbolt
9e9e035b28 Rephrase frontend imports (#7824)
- Removes `rootDirs` so all imports will be relative in the frontend
- Updates (and unifies) imports to be `../types/...` etc instead of
relying on "types" being in the rootDir for the frontend.
- Fixes one type that was being picked up from `lib` in the frontend.
- Adds a precommit hook to check in future

Paves the way to writing _unit_ tests for the frontend for the subset of
the frontend code we can import from `node` (which might be a lot of
it!)
2025-06-18 09:04:23 -05:00
Mats Jun Larsen
5dbb5fff15 Eliminate all usages of require() in the client (#7796) 2025-06-12 21:35:00 +00:00
Matt Godbolt
d0c16246d3 Fix null reference error in findConfig when URL parsing fails (#7763)
## Summary

Fixes `TypeError: Cannot read properties of undefined (reading
'content')` in `findConfig()` when URL parsing fails and no saved state
is available.

## Root Cause

This error occurs when:
1. `url.deserialiseState()` throws an exception due to
malformed/corrupted URLs
2. No saved state exists in localStorage
(`sessionThenLocalStorage.get('gl', null)` returns `null`)
3. Code attempts to access `config.content` when `config` is still
`undefined`

The error happens legitimately from truncated URLs, corrupted bookmarks,
or URL shortener issues.

## Changes

- Changed `if (!config.content || config.content.length === 0)` to use
optional chaining: `if (!config?.content || config.content?.length ===
0)`
- This gracefully handles the null/undefined case and falls back to
default config as intended

## Impact

- Maintains existing user experience (fallback to default config when
URL parsing fails)
- Prevents crash with 1430+ reported occurrences
- No behavioral changes for valid URLs

Fixes COMPILER-EXPLORER-DE3

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-06-06 14:28:56 -05:00
Matt Godbolt
1831edc227 Refactor startup to catch exceptions where they're thrown. (#7734)
Fixes issues with missing components (e.g. from beta, 'explain')

The issue was that the exceptions are thrown in `initLayout`, not in the
constructor.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-05-27 12:43:56 -05:00
Matt Godbolt
82eff66c49 Handle items that don't exist in embedded mode; fix iframe generation (#7605)
Checked locally. Have no idea how the heck the quotes got changed....
2025-04-24 14:09:02 -05:00
Matt Godbolt
637564f389 Migrate to Bootstrap 5 (#7582)
This PR completes the migration from Bootstrap 4 to Bootstrap 5.3.5
following the plan outlined in
[docs/Bootstrap5Migration.md](https://github.com/compiler-explorer/compiler-explorer/blob/mg/bootstrap5/docs/Bootstrap5Migration.md).

## Migration Process

We followed a phased approach as documented in the migration plan:

1. **Phase 1: Dependency Updates and Basic Setup**
   - Updated Bootstrap from 4.6.2 to 5.3.5
   - Added @popperjs/core dependency (replacing Popper.js)
   - Updated Tom Select theme from bootstrap4 to bootstrap5

2. **Phase 2: Global CSS Class Migration**
   - Updated directional utility classes (ml/mr → ms/me)
- Updated floating utility classes (float-left/right → float-start/end)
   - Updated text alignment classes (text-left/right → text-start/end)

3. **Phase 3: HTML Attribute Updates**
- Updated data attributes to use Bootstrap 5 prefixes (data-bs-toggle,
data-bs-target, etc.)
   - Fixed tab navigation issues

4. **Phase 4: JavaScript API Compatibility Layer**
   - Created bootstrap-utils.ts compatibility layer
- Updated component initialization for modals, dropdowns, popovers, etc.

5. **Phase 5: Component Migration**
- Updated and tested specific components (modals, dropdowns, toasts,
etc.)
   - Fixed styling issues in cards and button groups

6. **Phase 6: Form System Updates**
   - Updated form control classes to Bootstrap 5 standards
   - Updated checkbox/radio markup patterns
   - Simplified input groups

7. **Phase 7: Navbar Structure Updates**
   - Updated navbar structure with container-fluid
   - Fixed responsive behavior

8. **Phase 8: SCSS Variables and Theming**
   - Added custom CSS fixes for navbar alignment
   - Verified theme compatibility

9. **Phase 9: Accessibility Improvements**
   - Updated sr-only to visually-hidden
   - Added proper ARIA attributes
   - Enhanced screen reader support

## Key Changes

- No more jQuery dependency in Bootstrap 5
- New prefix for data attributes (data-bs-*)
- Improved accessibility with ARIA attributes
- Updated positioning classes (start/end instead of left/right)
- Simplified input group structure

## Test Plan

1. **Navigation Testing**
   - Verify all dropdown menus open and close properly
   - Test mobile menu responsiveness
   - Check tab navigation in settings dialog

2. **Component Testing**
- Verify all modals open and close correctly (settings, share,
load/save)
   - Test tooltips and popovers
   - Check form controls in different dialogs

3. **Layout Testing**
   - Test responsiveness on different screen sizes
   - Verify proper alignment of elements
   - Check dark mode compatibility

4. **Specific Features to Test**
   - Compiler selection and options
   - Share dialog functionality
   - Settings dialog
   - Tree view (IDE mode)
   - Font selection dropdown

5. **Browser Testing**
   - Test in Chrome, Firefox, Safari
   - Test in mobile browsers

## Note on Further Improvements

After this migration is stable, we could consider Phase 12: removing
jQuery dependency entirely, as Bootstrap 5 no longer requires it. This
would be a separate effort.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-04-24 12:10:37 -05:00
Ofek
d3ce34dca6 Fix #7398: call layout.init only after SiteSettings are in place (#7402) 2025-02-18 21:31:10 +02:00
Mats Jun Larsen
5eea63328f Migrate to Biome for linting and formatting (#7033) 2025-02-02 17:54:31 +00:00
Ofek
b75542bfac Fix #3264: move emitShortLinkEvent from editor-pane to main window (#7163)
When settings are set to emit-short-link upon ctrl+S, managing the logic
in `Editor` is problematic since the editor may lose focus and not
receive the event.

Also logically this is a cross-site event, and doesn't belong in any
particular editor (there can be multiple).
2024-12-02 10:41:12 +02:00
Ofek
20b8ccaa6f Remove ICompiler, other minor type fixes (#7079) 2024-11-25 18:36:20 +02:00
Ofek
caca3ea6c7 Eliminate all google-analytics dead code (#6954)
<!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE
IT
Thanks for taking the time to improve CE. We really appreciate it.
Before opening the PR, please make sure that the tests & linter pass
their checks,
  by running `make check`.
In the best case scenario, you are also adding tests to back up your
changes,
  but don't sweat it if you don't. We can discuss them at a later date.
Feel free to append your name to the CONTRIBUTORS.md file
Thanks again, we really appreciate this!
-->
2024-10-10 21:21:43 +03:00
Ofek Shilon
bce3a65d6d Add full-url capture for sentry messages triggered in front end 2024-06-03 22:11:52 +03:00
Ofek Shilon
0741ec2fdc Fix: page refresh restores default code 2024-05-11 17:29:11 +03:00
Ofek
44d48dca16 Fix #6464: defend against empty saved layout (#6465)
Fix #6464, following the discord discussion.

2 protections are added here:

(1) Make the first code editor non-closable, to avoid an empty layout,
(2) If a loaded config has empty layout - fallback to the default
config.
2024-05-10 11:24:11 +03:00
Jeremy
db3076e0ab Rescue users from real dark mode 2024-04-09 20:20:18 -05:00
Jeremy Rifkin
c2fa676a8e Create the real dark mode (#6309) 2024-03-31 19:41:51 -05:00
Matt Godbolt
e4b791ce92 Use session _then_ local storage for saved state (#5277)
In conversation with @mknejp he pointed out that it can be frustating
when having a browser loaded up with many tabs of CE links, then
reloading the browser (e.g. a reboot, or open/closing the tabs), that
upon reload all the tabs will have the same, shared state (corresponding
to whichever saved to local storage last).

This change:
- stores state in _both_ session and local storage
- removes from both on UI reset
- loads first from session storage and then falls back to local storage

The net result is:
- tabs reopened with "ctrl-shift T" will regain their prior state, as do
any other tabs for which the browser thinks are part of the same session
(like on a "reopen tabs" plugins etc)
- newly-opened tabs still have the prior behaviour of using whatever the
most recently opened tab had as its starting state

Some more info on session vs local storage
[here](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage)
2023-07-23 18:08:33 -05:00
Patrick Quist
0e85d8c388 Fix link datetime layout (#5263) 2023-07-18 02:26:35 +02:00
Patrick Quist
9b983d6965 Load and show creation_date of shortlink (#5236) 2023-07-17 23:36:36 +02:00
Jeremy Rifkin
4260313e13 Common utilities and type work (#5200)
This PR refactors some common utilities out of lib/ and into shared/ and
eliminates some use of underscore.js, as well as general type
improvements done along the way.
2023-06-28 20:13:10 -04:00
Jeremy Rifkin
9b69146add Move all styles to static/styles (#5210) 2023-06-28 08:06:45 -04:00
Jeremy Rifkin
e2ee803598 Improve sentry capturing of unhandled promise rejections (#5190) 2023-06-21 15:40:40 -04:00
Jeremy Rifkin
e267286553 Support user site templates (#5180)
Long overdue
![image](https://github.com/compiler-explorer/compiler-explorer/assets/51220084/d8a56216-d6b0-459a-8539-9f519c023b92)
![image](https://github.com/compiler-explorer/compiler-explorer/assets/51220084/133da5e6-2717-464a-a5fc-5983a3f75014)
2023-06-19 22:33:40 -04:00
Jeremy Rifkin
c779507000 Create a print view (#5161)
This PR adds a print view for CE

Closes #4617


![image](https://github.com/compiler-explorer/compiler-explorer/assets/51220084/92e5ceab-10cc-4289-a742-592e379627ef)

At the moment syntax highlighting isn't working. I think we need a way
to get style definitions from monaco. I've opened an issue at
https://github.com/microsoft/monaco-editor/issues/4031. For the CFG
pane, using the monaco classes "just works", but for some reason when
@media print is applied those definitions go away. We'd want to always
use light mode colors anyway.
2023-06-19 22:13:45 -04:00
Jeremy
653e9a6899 Lint fixes 2023-06-11 17:38:38 -04:00
Jeremy Rifkin
acdd5ad45c Capture errors in sentry better (#5128)
Fixes #5127 and similar issues.

Rationale: Whenever something that is not an Error object is passed to
Sentry.captureException we get pretty much no useful information in
sentry

![image](https://github.com/compiler-explorer/compiler-explorer/assets/51220084/c7345449-f7a0-46cb-a198-abe0bd80a8b1)
(usually not even a stacktrace)
2023-06-11 17:31:51 -04:00
Jeremy Rifkin
0bc22f8883 Egregiously overengineered fix for a niche UI bug (#5074)
Fixes #4714
2023-05-30 21:11:21 -05:00
Jeremy Rifkin
55b82bb12c Turn off april fools mode (#4927)
This PR has the changes to remove the pink banner once we are ready to do so
2023-04-02 19:31:46 -05:00
Jeremy Rifkin
5d8d39f136 Pink (#4916) 2023-04-01 00:52:27 -04:00
Jeremy Rifkin
01935ecb2a Ensure a default language is provided for new editor panes (#4890)
Fixes #4889
2023-03-20 17:03:42 -04:00
Jeremy Rifkin
bbabd514a5 Update error alert styling (#4860)
![image](https://user-images.githubusercontent.com/51220084/224565888-e0b98abf-6e1c-4914-8695-b31a2275b364.png)
2023-03-12 17:03:36 -04:00
Mats Jun Larsen
633eb82d18 Transition to ECMAScript Modules (#4780)
Makes the Compiler Explorer app, and all the tooling ESM compatible.
Things that have been done:

1. The package.json has `type: module` now
2. All relative imports have a .js ending
3. All directory imports are now directory/index.js to comply with ESM
standards
4. Dependency node-graceful is now imported into tree, because the
package is broken under esm
5. Dependency p-queue has been bumped to 7.x with ESM support
6. Dependency profanities has been bumped to 3.x with ESM support
7. Webpack config is now both ESM and CommonJS compatible
8. Non-ESM compatible imports have been rewritten
9. ESLint configuration has been tweaked to not fail on .js imports
10. Mocha is now hacked together and ran with ts-node-esm
11. Webpack is now hacked together and ran with ts-node-esm
12. Webpack config is now ESM compatible, so that it can be used in the
dev server
13. Cypress code still runs commonjs, and has been excluded from the
tsconfig
14. All sinon mock tests have been commented out, because sinon module
mocks do not work with ESModules (because ESModules are immutable)

A lot of tests are now giving warnings/errors to stdout, yet still pass.
Docenizer codegenerator scripts have been updated, but I did not re-run
them, and instead just changed their code.

---------

Co-authored-by: Matt Godbolt <matt@godbolt.org>
2023-02-27 18:06:38 -06:00
Jeremy Rifkin
384c297906 Fix trailing comma issue (#4775)
Make trailing commas more consistent throughout the project, fixes
config conflict between eslint and prettier. Resolves an oversight in
#4766.
2023-02-26 12:21:35 -05:00
Jeremy Rifkin
3f9813a3bb Rison error handling (#4594) 2023-01-13 23:50:36 -05:00
Jeremy Rifkin
33167a3024 Tsify main (#4520) 2023-01-13 19:52:00 -05:00