From 994911d3e4e4139ed1ec42d10ef444a18969a63b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Sep 2025 02:35:31 -0700 Subject: [PATCH 1/6] Remove the long-dead cyan trick. --- src/entrypoints/content.ts | 18 ------------------ src/lib/config.ts | 1 - 2 files changed, 19 deletions(-) diff --git a/src/entrypoints/content.ts b/src/entrypoints/content.ts index 3136329..5dc5122 100644 --- a/src/entrypoints/content.ts +++ b/src/entrypoints/content.ts @@ -1,4 +1,3 @@ -import { CONFIG } from '../lib/config' import type { CommentEvent, CommentSpot, StrippedLocation } from '../lib/enhancer' import { logger } from '../lib/logger' import { EnhancerRegistry, TextareaRegistry } from '../lib/registries' @@ -98,8 +97,6 @@ function enhanceMaybe(textarea: HTMLTextAreaElement) { logger.debug('textarea already registered {}', textarea) return } - - injectStyles() try { const location = detectLocation() logger.debug('[gitcasso] Calling tryToEnhance with location:', location) @@ -118,18 +115,3 @@ function enhanceMaybe(textarea: HTMLTextAreaElement) { logger.error(e) } } - -const STYLES = ` -.${CONFIG.ADDED_OVERTYPE_CLASS} { - background: cyan !important; -} -` - -function injectStyles(): void { - if (!document.getElementById('gitcasso-styles')) { - const style = document.createElement('style') - style.textContent = STYLES - style.id = 'gitcasso-styles' - document.head.appendChild(style) - } -} diff --git a/src/lib/config.ts b/src/lib/config.ts index 74b71b2..a98e375 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -7,7 +7,6 @@ const LOG_LEVELS = ['DEBUG', 'INFO', 'WARN', 'ERROR'] as const export type LogLevel = (typeof LOG_LEVELS)[number] export const CONFIG = { - ADDED_OVERTYPE_CLASS: 'gitcasso-overtype', EXTENSION_NAME: 'gitcasso', // decorates logs LOG_LEVEL: 'DEBUG' satisfies LogLevel, MODE: 'PROD' satisfies ModeType, From 180b68473c2b4efd76421f5593c947e01d49229e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Sep 2025 02:45:24 -0700 Subject: [PATCH 2/6] githubSpotTypes is dead --- src/lib/enhancers/github/githubSpotTypes.ts | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/lib/enhancers/github/githubSpotTypes.ts diff --git a/src/lib/enhancers/github/githubSpotTypes.ts b/src/lib/enhancers/github/githubSpotTypes.ts deleted file mode 100644 index 73646ab..0000000 --- a/src/lib/enhancers/github/githubSpotTypes.ts +++ /dev/null @@ -1,13 +0,0 @@ -export const GITHUB_SPOT_TYPES = [ - 'GH_PR_ADD_COMMENT', - 'GH_ISSUE_ADD_COMMENT', - /* TODO - 'GH_ISSUE_NEW', - 'GH_PR_NEW', - 'GH_ISSUE_EDIT_COMMENT', - 'GH_PR_EDIT_COMMENT', - 'GH_PR_CODE_COMMENT', - */ -] as const - -export type GitHubSpotType = (typeof GITHUB_SPOT_TYPES)[number] From cb539036e1b15e8336aade3435eae12aac0fc266 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Sep 2025 02:39:08 -0700 Subject: [PATCH 3/6] Remove the infrastructure for `prepareForFirstEnhancement()` --- src/lib/enhancer.ts | 4 ---- src/lib/enhancers/CommentEnhancerMissing.tsx | 3 --- src/lib/registries.ts | 6 ------ 3 files changed, 13 deletions(-) diff --git a/src/lib/enhancer.ts b/src/lib/enhancer.ts index d835c4c..56dc6a4 100644 --- a/src/lib/enhancer.ts +++ b/src/lib/enhancer.ts @@ -37,12 +37,8 @@ export interface CommentEnhancer { * If we return non-null, then we become the handler for that text area. */ tryToEnhance(textarea: HTMLTextAreaElement, location: StrippedLocation): Spot | null - /** This gets called the first time that `tryToEnhance` returns non-null. */ - prepareForFirstEnhancement(): void /** * If `tryToEnhance` returns non-null, then this gets called. - * It is guaranteed that `prepareForFirstEnhancement` has been called - * exactly once since pageload before this gets called. */ enhance(textarea: HTMLTextAreaElement, spot: Spot): OverTypeInstance /** Returns a ReactNode which will be displayed in the table row. */ diff --git a/src/lib/enhancers/CommentEnhancerMissing.tsx b/src/lib/enhancers/CommentEnhancerMissing.tsx index f59a6e6..b123e1c 100644 --- a/src/lib/enhancers/CommentEnhancerMissing.tsx +++ b/src/lib/enhancers/CommentEnhancerMissing.tsx @@ -43,9 +43,6 @@ export class CommentEnhancerMissing implements CommentEnhancer { tryToEnhance(_textarea: HTMLTextAreaElement, _location: StrippedLocation): CommentSpot | null { throw new Error('Method not implemented.') } - prepareForFirstEnhancement(): void { - throw new Error('Method not implemented.') - } enhance(_textarea: HTMLTextAreaElement, _spot: CommentSpot): OverTypeInstance { throw new Error('Method not implemented.') } diff --git a/src/lib/registries.ts b/src/lib/registries.ts index 534d688..3a08e98 100644 --- a/src/lib/registries.ts +++ b/src/lib/registries.ts @@ -17,7 +17,6 @@ export interface EnhancedTextarea { export class EnhancerRegistry { private enhancers = new Set() - private preparedEnhancers = new Set() byType = new Map() constructor() { @@ -66,11 +65,6 @@ export class EnhancerRegistry { try { const spot = enhancer.tryToEnhance(textarea, location) if (spot) { - // Prepare enhancer on first use - if (!this.preparedEnhancers.has(enhancer)) { - enhancer.prepareForFirstEnhancement() - this.preparedEnhancers.add(enhancer) - } const overtype = enhancer.enhance(textarea, spot) this.handleDelayedValueInjection(overtype) return { enhancer, overtype, spot, textarea } From 387f330a917dcb85386ccbad6943e240fdddde1c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Sep 2025 02:47:46 -0700 Subject: [PATCH 4/6] Add a `oncePerRefresh` function. --- src/lib/once-per-refresh.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/lib/once-per-refresh.ts diff --git a/src/lib/once-per-refresh.ts b/src/lib/once-per-refresh.ts new file mode 100644 index 0000000..c5c57ce --- /dev/null +++ b/src/lib/once-per-refresh.ts @@ -0,0 +1,13 @@ +const hasRunSinceTheLastFullPageload = new Set() + +/** + * This function helps you run a given function only once per full pageload. + * So this will not run again due to turbolink navigation. + */ +export function oncePerRefresh(key: string, fun: () => void) { + if (hasRunSinceTheLastFullPageload.has(key)) { + return + } + fun() + hasRunSinceTheLastFullPageload.add(key) +} From 3b61953992b4f824707a5dafd76e2b794f939795 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 18 Sep 2025 02:48:03 -0700 Subject: [PATCH 5/6] Refactor all the gihub highlighters to use `oncePerRefresh`. --- src/lib/enhancers/github/githubEditComment.tsx | 7 ++----- src/lib/enhancers/github/githubHighlighter.ts | 10 +++++++++- src/lib/enhancers/github/githubIssueAddComment.tsx | 7 ++----- src/lib/enhancers/github/githubIssueNewComment.tsx | 7 ++----- src/lib/enhancers/github/githubPRAddComment.tsx | 7 ++----- src/lib/enhancers/github/githubPRNewComment.tsx | 7 ++----- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/lib/enhancers/github/githubEditComment.tsx b/src/lib/enhancers/github/githubEditComment.tsx index a457ae6..4f6ea46 100644 --- a/src/lib/enhancers/github/githubEditComment.tsx +++ b/src/lib/enhancers/github/githubEditComment.tsx @@ -4,7 +4,7 @@ import type { CommentEnhancer, CommentSpot } from '@/lib/enhancer' import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' import { commonGithubOptions } from './ghOptions' -import { githubHighlighter } from './githubHighlighter' +import { prepareGitHubHighlighter } from './githubHighlighter' export interface GitHubEditCommentSpot extends CommentSpot { type: 'GH_EDIT_COMMENT' @@ -48,11 +48,8 @@ export class GitHubEditCommentEnhancer implements CommentEnhancer { + OverType.setCodeHighlighter(githubHighlighter) + }) +} + +function githubHighlighter(code: string, language?: string) { try { if (language && hljs.getLanguage(language)) { const result = hljs.highlight(code, { language }) diff --git a/src/lib/enhancers/github/githubIssueAddComment.tsx b/src/lib/enhancers/github/githubIssueAddComment.tsx index 233508d..a36de96 100644 --- a/src/lib/enhancers/github/githubIssueAddComment.tsx +++ b/src/lib/enhancers/github/githubIssueAddComment.tsx @@ -5,7 +5,7 @@ import type { CommentEnhancer, CommentSpot, StrippedLocation } from '@/lib/enhan import { logger } from '@/lib/logger' import { modifyDOM } from '../modifyDOM' import { commonGithubOptions } from './ghOptions' -import { githubHighlighter } from './githubHighlighter' +import { prepareGitHubHighlighter } from './githubHighlighter' export interface GitHubIssueAddCommentSpot extends CommentSpot { type: 'GH_ISSUE_ADD_COMMENT' @@ -53,11 +53,8 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer Date: Thu, 18 Sep 2025 02:53:55 -0700 Subject: [PATCH 6/6] Fix some problems with `corpus-view` from the earlier refactor. --- tests/corpus-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/corpus-view.ts b/tests/corpus-view.ts index b7fdd00..464bf59 100644 --- a/tests/corpus-view.ts +++ b/tests/corpus-view.ts @@ -329,7 +329,7 @@ app.post('/rebuild', async (_req, res) => { // Run pnpm run build:dev const buildProcess = spawn('pnpm', ['run', 'build:dev'], { - cwd: path.join(__dirname, '..', '..'), + cwd: path.join(__dirname, '..'), stdio: ['pipe', 'pipe', 'pipe'], })