Skip to content

fix(ImagePicker): a forwarded ref was read through an optional chain inside the call - #23

Merged
thinkclay merged 1 commit into
mainfrom
fix/unsafe-optional-chaining-file-picker
Aug 27, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/unsafe-optional-chaining-file-picker

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

What

useFilePicker's getInputProps guards the caller's ref and then invokes it:

if (typeof (opts?.ref as (el: HTMLInputElement | null) => void) === 'function') {
  ;(opts?.ref as (el: HTMLInputElement | null) => void)(el)
}

The cast is what makes this look safe. It erases undefined from the type, so
typeof … === 'function' narrows nothing, and the call site reads as
(undefined)(el) to the checker. The runtime behaviour was fine — the guard is
real — but the code says something it does not mean.

Why now

biome 2.5.x promotes lint/correctness/noUnsafeOptionalChaining to an error
and flags exactly this site. It is one of the two sites holding the biome
2.4.9 → 2.5.10 bump back in the consuming monorepo (Scaffald/SaaS#510); the
other one lives there and is fixed in the same wave.

The fix

Read opts?.ref into a local first, so the typeof check narrows it before the
call. The cast survives only as the call signature, applied to an already-narrowed
value.

Verification

  • pnpm lint under biome 2.5.10: 0 errors, 30 warnings (unchanged).
    Same command with this commit reverted: 1 error at
    src/components/ImagePicker/useFilePicker.ts:42.
  • Behaviour unchanged — no test or snapshot moved.

Refs Scaffald/SaaS#510

…inside the call

`getInputProps` guarded the caller's `ref` with `typeof (opts?.ref as …) ===
'function'`, then invoked `(opts?.ref as …)(el)`. The cast is what makes this
look safe: it erases `undefined` from the type, so the guard narrows nothing and
the call site is `(undefined)(el)` as far as the checker is concerned.

biome 2.5.x promotes lint/correctness/noUnsafeOptionalChaining to an error and
flags exactly this, which is currently holding the biome bump back in the
consuming monorepo (Scaffald/SaaS#510).

Read `opts?.ref` into a local first, so `typeof … === 'function'` genuinely
narrows it before the call. Behaviour is unchanged.
@thinkclay
thinkclay merged commit 4dcf8f8 into main Aug 27, 2026
@thinkclay
thinkclay deleted the fix/unsafe-optional-chaining-file-picker branch August 27, 2026 18:06
thinkclay added a commit to Scaffald/SaaS that referenced this pull request Aug 27, 2026
…ock the biome bump

Lands the five open dependabot PRs as one revertible commit. Four of them touch
pnpm-lock.yaml and the catalog, so they conflict pairwise and cannot merge
independently; the lockfile here is regenerated from scratch rather than merged.

Taken:

* actions   pnpm/action-setup v6.0.9 → v6.0.10 across five workflows (#550)
* dev       @nx/* and nx 22.7.7 → 22.7.8, @vitest/ui 4.1.10 → 4.1.11 (#641)
* test      @testing-library/user-event 14.5.2 → 14.6.5 (#551)
* backend   @sentry/react 10.69 → 10.70, posthog-js 1.407 → 1.418,
            posthog-react-native 4.61 → 4.63, posthog-node 5.46 → 5.50 (#619)
* misc      @hookform/resolvers 5.5.7 → 5.9.1, react-hook-form 7.83 → 7.85,
            fast-xml-parser 5.10.1 → 5.11.0, mapbox-gl 3.27 → 3.29,
            supabase CLI 2.110.0 → 2.115.0, swr 2.4.2 → 2.5.1,
            zustand 5.0.14 → 5.0.15, pg 8.22 → 8.23, @types/pg, uuid,
            baseline-browser-mapping, flow-remove-types (#642)

Two bumps are held back, each with the comment already on its catalog entry:

* @rnmapbox/maps 10.1.45 → 10.3.5 still pulls MapboxCommon 24.x from Mapbox's
  gated downloads API, and MAPBOX_DOWNLOADS_TOKEN is still set in no env file
  and no EAS environment — so `pod install` still 403s and the iOS build still
  breaks. Second wave in a row; see #509. Note mapbox-gl 3.29.0 IS taken: that
  is the web GL library and never touches the CocoaPods path.

* @supabase/supabase-js — dependabot moved the catalog to ~2.112.3 while the
  pnpm override still says ~2.86.0, which is #453 verbatim. lint:overrides
  would have caught it. The build-time half of the block is gone (#512 moved
  the EAS builder to Node 22 and validated it), but the 2.86 → 2.110 auth and
  realtime surface has not been runtime-validated, and that belongs in its own
  PR rather than inside a dependency batch.

@biomejs/biome 2.4.9 → 2.5.10 was the third hold-back. It is taken here, because
the two sites blocking it are fixed (#510):

* packages/supabase completion.router.ts guarded `preferencesData?.user_types`
  with Array.isArray and then read it back through a `as string[]` cast. The
  cast erases undefined, so the guard narrowed nothing. Reading it into a local
  first makes the narrowing real and drops the cast — the filter now carries a
  type predicate instead.

* packages/ui useFilePicker.ts had the same shape around a forwarded ref, and
  lives in the submodule. Fixed in Scaffald/ui#23, which main already carries
  via the pointer at Scaffald/ui#25.

2.5.10 also errors on one site 2.5.5 did not: reviews.ts built its grouping map
with `(grouped[key] ??= []).push(skill)`, which trips noAssignInExpressions.
Rewritten as three statements.

Also: the supabase CLI's local stack writes a minified bundle into
packages/supabase/.temp/start-secrets, which biome linted and failed on. That
path is generated output — added to the biome ignore list beside the other
generated paths.

@vitejs/plugin-react 5.1.3 → 6.1.0 rides along, closing #456. Its only hard
peer is vite ^8.0.0 and vite 8.0.14 already resolves here; the other three peers
are optional. packages/sdk/examples/react stays on 5.x — it is in the sdk
submodule and not worth a pointer bump for an example app.

Verified locally, since CI is billing-blocked (#375). nx cache reset first, in a
clean worktree off main with both submodule dists rebuilt — a stale packages/ui
dist reports a misleading `has no exported member 'ListToolbar'` at typecheck,
and an unbuilt packages/sdk dist reports `Cannot find module '@scaffald/sdk'`.
  pnpm check (locales + lint 10 projects + typecheck 12 projects)  pass
  pnpm lint:routes / lint:sorted-keys / lint:overrides             pass
  @scaffald/sdk                                                    783/783 pass
  nx run-many -t test                                              at parity

scf-core:test reports 12 failures, 1128/1198 passing. They are pre-existing on
main — baselined with the batch stashed, same twelve test names — and are now
tracked as #661.

Closes #550, closes #551, closes #619, closes #641, closes #642
Closes #456, closes #510
Refs #453, refs #509, refs #661

Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay added a commit to Scaffald/SaaS that referenced this pull request Aug 27, 2026
…ock the biome bump (#668)

Lands the five open dependabot PRs as one revertible commit. Four of them touch
pnpm-lock.yaml and the catalog, so they conflict pairwise and cannot merge
independently; the lockfile here is regenerated from scratch rather than merged.

Taken:

* actions   pnpm/action-setup v6.0.9 → v6.0.10 across five workflows (#550)
* dev       @nx/* and nx 22.7.7 → 22.7.8, @vitest/ui 4.1.10 → 4.1.11 (#641)
* test      @testing-library/user-event 14.5.2 → 14.6.5 (#551)
* backend   @sentry/react 10.69 → 10.70, posthog-js 1.407 → 1.418,
            posthog-react-native 4.61 → 4.63, posthog-node 5.46 → 5.50 (#619)
* misc      @hookform/resolvers 5.5.7 → 5.9.1, react-hook-form 7.83 → 7.85,
            fast-xml-parser 5.10.1 → 5.11.0, mapbox-gl 3.27 → 3.29,
            supabase CLI 2.110.0 → 2.115.0, swr 2.4.2 → 2.5.1,
            zustand 5.0.14 → 5.0.15, pg 8.22 → 8.23, @types/pg, uuid,
            baseline-browser-mapping, flow-remove-types (#642)

Two bumps are held back, each with the comment already on its catalog entry:

* @rnmapbox/maps 10.1.45 → 10.3.5 still pulls MapboxCommon 24.x from Mapbox's
  gated downloads API, and MAPBOX_DOWNLOADS_TOKEN is still set in no env file
  and no EAS environment — so `pod install` still 403s and the iOS build still
  breaks. Second wave in a row; see #509. Note mapbox-gl 3.29.0 IS taken: that
  is the web GL library and never touches the CocoaPods path.

* @supabase/supabase-js — dependabot moved the catalog to ~2.112.3 while the
  pnpm override still says ~2.86.0, which is #453 verbatim. lint:overrides
  would have caught it. The build-time half of the block is gone (#512 moved
  the EAS builder to Node 22 and validated it), but the 2.86 → 2.110 auth and
  realtime surface has not been runtime-validated, and that belongs in its own
  PR rather than inside a dependency batch.

@biomejs/biome 2.4.9 → 2.5.10 was the third hold-back. It is taken here, because
the two sites blocking it are fixed (#510):

* packages/supabase completion.router.ts guarded `preferencesData?.user_types`
  with Array.isArray and then read it back through a `as string[]` cast. The
  cast erases undefined, so the guard narrowed nothing. Reading it into a local
  first makes the narrowing real and drops the cast — the filter now carries a
  type predicate instead.

* packages/ui useFilePicker.ts had the same shape around a forwarded ref, and
  lives in the submodule. Fixed in Scaffald/ui#23, which main already carries
  via the pointer at Scaffald/ui#25.

2.5.10 also errors on one site 2.5.5 did not: reviews.ts built its grouping map
with `(grouped[key] ??= []).push(skill)`, which trips noAssignInExpressions.
Rewritten as three statements.

Also: the supabase CLI's local stack writes a minified bundle into
packages/supabase/.temp/start-secrets, which biome linted and failed on. That
path is generated output — added to the biome ignore list beside the other
generated paths.

@vitejs/plugin-react 5.1.3 → 6.1.0 rides along, closing #456. Its only hard
peer is vite ^8.0.0 and vite 8.0.14 already resolves here; the other three peers
are optional. packages/sdk/examples/react stays on 5.x — it is in the sdk
submodule and not worth a pointer bump for an example app.

Verified locally, since CI is billing-blocked (#375). nx cache reset first, in a
clean worktree off main with both submodule dists rebuilt — a stale packages/ui
dist reports a misleading `has no exported member 'ListToolbar'` at typecheck,
and an unbuilt packages/sdk dist reports `Cannot find module '@scaffald/sdk'`.
  pnpm check (locales + lint 10 projects + typecheck 12 projects)  pass
  pnpm lint:routes / lint:sorted-keys / lint:overrides             pass
  @scaffald/sdk                                                    783/783 pass
  nx run-many -t test                                              at parity

scf-core:test reports 12 failures, 1128/1198 passing. They are pre-existing on
main — baselined with the batch stashed, same twelve test names — and are now
tracked as #661.

Closes #550, closes #551, closes #619, closes #641, closes #642
Closes #456, closes #510
Refs #453, refs #509, refs #661

Co-authored-by: Claude Opus 5 <[email protected]>
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.

1 participant