RocketChat / RocketChat/Rocket.Chat
Refactor CodeMirror hook to remove unsafe annotation access and align with official API
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
Title
Refactor CodeMirror hook to remove unsafe annotation access and align with official API
Description
In the current implementation of the CodeMirror hook, transaction annotations are accessed using a non-standard approach:
// @ts-expect-error
update?.transactions[0]?.annotations?.length === 1
This relies on bypassing TypeScript checks and accessing internal properties that are not part of the official CodeMirror API.
Problem
Uses @ts-expect-error, which hides type safety issues
Accesses non-typed/internal transaction properties
Not aligned with recommended CodeMirror patterns
Can lead to fragile or hard-to-maintain code
Proposed Solution
Refactor the implementation to use CodeMirror’s official Annotation API:
Define a custom annotation using Annotation.define
Attach the annotation during programmatic dispatch
Read it safely using transaction.annotation(...)
Example
const dispatchAnnotation = Annotation.define<boolean>();
view.dispatch({
changes: { ... },
annotations: dispatchAnnotation.of(true),
});
const isDispatch = transaction.annotation(dispatchAnnotation) === true;
Benefits
Removes the need for @ts-expect-error
Improves type safety
Aligns with CodeMirror best practices
Makes the code more maintainable and predictable
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the CodeMirror hook containing the transaction annotation access and inspect its programmatic dispatch path. Replace the internal transaction-property access with a defined CodeMirror annotation, then verify that dispatches attach it and transactions read it through the official annotation API without the TypeScript suppression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100