Skip to content

fix(browser-extension): guard project name against null textContent - #1636

Open
Agnik47 wants to merge 1 commit into
supermemoryai:mainfrom
Agnik47:fix/browser-extension-null-textcontent
Open

fix(browser-extension): guard project name against null textContent#1636
Agnik47 wants to merge 1 commit into
supermemoryai:mainfrom
Agnik47:fix/browser-extension-null-textcontent

Conversation

@Agnik47

@Agnik47 Agnik47 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #1561

Problem

createProjectSelectionModal declares its onImport callback with a non-nullable name (utils/ui-components.ts:405-411), but the call site passes Node.textContent, typed string | null:

utils/ui-components.ts(611,13): error TS2345:
Argument of type '{ id: string; name: string | null; containerTag: string; }'
is not assignable to parameter of type '{ id: string; name: string; containerTag: string; }'.

Fix

Fall back to an empty string. This matches the containerTag line directly below it and every other .textContent read in the extension — this was the only unguarded site.

selectedOption.text was considered instead (it is typed non-nullable), but rejected: per spec it strips and collapses whitespace, which would silently alter project names.

Runtime behaviour is unchanged. Options are built with option.textContent = project.name (ui-components.ts:516-518), so the value is always a string, and the disabled placeholder carries value = "", so the existing if (selectedOption.value) guard already excludes it. This is a type-safety fix only.

One correction to the issue report

The issue states the lockfile pins TypeScript 5.8.3 as a single entry that this workspace dedupes onto. That is not what the current lockfile resolves: bun install --frozen-lockfile gives apps/browser-extension its own nested typescript@5.9.3 (the root copy is 5.8.3, but the extension does not use it).

TS 5.9's DOM lib types textContent as non-nullable on Element, so check-types currently passes on main as CI would install it — the error only appears under 5.8.x, which the package's own ^5.8.3 range still permits.

So this is a latent defect rather than a red build today. Verified both ways:

main with this PR
TS 5.9.3 (lockfile resolution) passes passes
TS 5.8.3 TS2345, the package's only error passes

Preventing recurrence

apps/browser-extension is not type-checked in CI, which is why this sat on main. This PR adds a change-gated check-types step following the existing SDK/playground detection pattern, so it runs only when apps/browser-extension changes.

Happy to drop the CI half if you'd rather keep this PR to the one-line fix.

Verification

  • bun run --cwd apps/browser-extension check-types exits 0 under both TypeScript versions above; the TS2345 was the only error reported under 5.8.3
  • bun test in apps/browser-extension: 12 pass, 0 fail
  • biome check on the changed line is clean (the file reports a pre-existing CRLF diff on a Windows checkout only, identical before and after this change; the repo stores LF)

🤖 Generated with Claude Code

https://claude.ai/code/session_017QSriDRoFLVze1BZGrAJHV

`createProjectSelectionModal` declares its `onImport` callback with a
non-nullable `name`, but the call site passed `Node.textContent`, which the
DOM lib types as `string | null` under `Node`:

    utils/ui-components.ts(611,13): error TS2345:
    Argument of type '{ id: string; name: string | null; containerTag: string; }'
    is not assignable to parameter of type '{ id: string; name: string; containerTag: string; }'.

Fall back to an empty string, matching the `containerTag` line directly below
it and every other `.textContent` read in the extension.

Runtime behaviour is unchanged: the options are built with
`option.textContent = project.name`, so the value is always a string, and the
disabled placeholder carries `value = ""` so the `if (selectedOption.value)`
guard already excludes it.

Also add a change-gated browser-extension `check-types` step to CI. The package
was never type-checked there, which is why this survived on main; the step
follows the existing SDK/playground detection pattern so it only runs when
apps/browser-extension changes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017QSriDRoFLVze1BZGrAJHV
@polylane

polylane Bot commented Sep 1, 2026

Copy link
Copy Markdown

Note

Production impact unlikely.

No production resources are plausibly affected by this change.

review-in-polylane disable-pr-reviews

Polylane analysed cdb9a9c for production impact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

check-types fails on main for the browser extension: textContent (string | null) passed where string is required

1 participant