Repository navigation
refactor(platform): split useSidebarState and useAccessibilityInfo into platform extensions - #3
Merged
Merged
Conversation
…to platform extensions Both hooks previously branched on `Platform.OS` at runtime, with `useAccessibilityInfo` further confused by living under `platform/native/` despite handling web inside the same file. Splitting them into `.web.ts` / `.native.ts` lets Metro resolve the right implementation at build time — feature code imports one name and never sees a runtime branch. - `useSidebarState`: persists via localStorage on web (sync initial read) and AsyncStorage on native (async hydrate). - `useAccessibilityInfo`: web reads `prefers-reduced-motion` etc. via matchMedia; native reads from `AccessibilityInfo` + subscribes to change events. Co-Authored-By: Claude Opus 4.7 <[email protected]>
6 of 13 tasks
thinkclay
added a commit
to Scaffald/SaaS
that referenced
this pull request
May 19, 2026
…s (iOS crash fix) (#249) * refactor(platform): introduce cross-platform primitives and migrate ~50 call-sites Adds `@scf/core/utils/platform/*` — a set of Metro platform-extension primitives that replace scattered `Platform.OS === 'web'` branches and unguarded `window.*` / `document.*` / `localStorage` access throughout feature code. The original symptom that prompted this audit was an iOS ErrorBoundary crash from `window.addEventListener is not a function` in profile screens (`window` exists on RN as the global object, so `typeof window === 'undefined'` guards silently failed). ## New primitives (each as .ts shared shape + .web.ts + .native.ts) - `openExternalLink(url, { inApp? })` — `window.open` / `Linking.openURL` (plus optional `expo-web-browser` in-app browser on native). - `useUnsavedChangesPrompt(isDirty)` — replaces the 4× duplicated `beforeunload` `useEffect` block in profile screens. Native attaches `navigation.addListener('beforeRemove', ...)` for a native Alert. - `confirmDialog({ title, message, destructive? })` — promise-wrapped `window.confirm` / `Alert.alert` (so native no longer silently no-ops). - `kvStorage` (localStorage / AsyncStorage) + `sessionKvStorage` (sessionStorage / in-memory Map) — async key/value with consistent shape across both platforms. - `downloadFile({ url, filename })` — anchor-click trick on web, `Linking.openURL` on native. - `pickFile({ accept, multiple? })` — hidden file-input on web, `expo-document-picker` on native; returns a uniform `PickedFile[]`. - `getCanonicalUrl(path)` — `${origin}${path}` on web, `undefined` on native (SEO is a web-only concept). - `setDocumentTitle(title)` — `document.title =` on web, no-op on native (use `navigation.setOptions({ title })`). - `reloadPage()` — `window.location.reload()` on web, no-op on native (callers should `queryClient.invalidateQueries` for parity). ## Migrations (~50 files) - 12× `window.open` → `openExternalLink` (profile certifications, discover modals/hover cards, privacy, news, admin background checks, oauth consent). - 4× `beforeunload` `useEffect` blocks → `useUnsavedChangesPrompt` (profile education/experience/general/skills + `useSaveStatus`). - `window.confirm` in TasksDetail + DeveloperPortal → `confirmDialog`. - `window.location.href` in AccountSwitcher + admin cms → `router.push` / `reloadPage`; oauth ConsentScreen → `openExternalLink`. - `localStorage` / `sessionStorage` direct access in MapStateProvider, ProfileCompletion, useCompletionNudges, oauth/passthrough, feedbackStorage, UniversalThemeProvider → `kvStorage` / `sessionKvStorage`. - File-download anchor tricks in payments + ConnectionsList → `downloadFile`. - File-picker `<input type=file>` + `document.getElementById().click()` in profile certifications → `pickFile`. - Canonical-URL builders in `apps/scaffald/(public)/jobs/[slug]` and IPIP share results → `getCanonicalUrl`. - `document.title` writes in `usePageTitle` web branch + JobSeoHead → `setDocumentTitle`. ## Platform-extension splits (companion to packages/ui PR) - `useUserLocation` split into shared `.ts` shape + existing `.native.ts` + new `.web.ts` (was a single `.ts` doing runtime branching). - `packages/ui` submodule bump to include the parallel `useSidebarState` and `useAccessibilityInfo` splits (see Scaffald/ui#3). ## Other clean-ups - Removes `hooks/useSafeToast.ts` — was a defensive wrapper around an old beyond-ui toast bug (string-matching error messages). Sole consumer (`profile-general-left`) now uses `useToast` directly. - Collapses `publicProfileUrl.openPublicProfileInNewTab` into a thin wrapper around `openExternalLink`. ## Guardrail - New `scripts/check-platform-leakage.sh` + `pnpm lint:platform` flags browser-DOM/BOM API use outside platform-extension files. Wired into `pnpm lint:affected`. 5 surviving call-sites are annotated with `// platform-allow: <reason>` (web-only debug flags, web-only map pins, etc.) — see the script for the allow-list rules. Co-Authored-By: Claude Opus 4.7 <[email protected]> * fix(build): break fork-bomb recursion in nx run-many -t build The root package.json defines `build` as `pnpm locales:validate && nx run-many -t build --exclude=@scaffald/ui-docs`. Nx's @nx/js auto-discovery picks up that script and adds a `build` target on the root `scaffald` project itself. When `nx run-many -t build` runs, it sees the root project as a candidate, invokes its `build` target (which calls `pnpm build` again), and recurses without bound — each pass forks a new `pnpm` + `sh` + `nx run-many` + `run-executor` quartet. A single `pnpm prepush` ballooned to 260+ processes within three minutes during this branch's push attempt. Fix by excluding the root project from the recursive invocations: - `affected:build`: `--exclude=scaffald` - `build`: `--exclude=@scaffald/ui-docs,scaffald` - `prepush`: `--exclude=scaffald` on the affected-build leg and `--exclude=...,scaffald` on the test leg The root project never had a useful build artifact — its `build` script is an orchestrator, not a build target — so excluding it from the run-many sweep is the right thing regardless of the fork bomb fix. Co-Authored-By: Claude Opus 4.7 <[email protected]> * refactor(communities): remove floating search/sort toolbar on mobile The bottom toolbar's floating glass buttons conflicted with the bottom tab navigator. Desktop search/sort via PageHeader is unchanged. Co-Authored-By: Claude Opus 4.7 <[email protected]> * chore(gitignore): ignore Next.js build artifacts in apps/web `apps/web/.next/` (91MB build cache) and `apps/web/next-env.d.ts` (auto-regenerated by every `next build`) were leaking into `git status` after `pnpm prepush` ran. Neither has ever been tracked. Add both to the root `.gitignore` so they stop tripping `gh pr create`'s uncommitted-changes warning. `next-env.d.ts` is regenerated on demand by Next.js so ignoring it costs nothing. Co-Authored-By: Claude Opus 4.7 <[email protected]> --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
3 of 4 tasks
thinkclay
added a commit
to Scaffald/SaaS
that referenced
this pull request
May 19, 2026
… ui#3 (#250) * chore: untrack .claude/launch.json (already in .gitignore) The file predates the `.claude/` ignore rule (added later in .gitignore). It has only ever been edited by one developer, and the team's intent — per the existing ignore rule — is that everything under `.claude/` is per-developer config. Removing it from the index brings the actual git state into alignment with the gitignore. The file stays on each developer's disk where they already had it; this commit only removes the tracked copy. Future edits no longer pollute `git status` or trip `gh pr create`'s uncommitted-changes warning. Co-Authored-By: Claude Opus 4.7 <[email protected]> * chore(ui): bump submodule pointer to include merged platform-extensions PR Pulls in Scaffald/ui#3 (5067e50, merged) which split `useSidebarState` and `useAccessibilityInfo` into Metro platform extensions (`.web.ts` / `.native.ts`). The companion to UNI-Construct#249. The previous pointer (7907ee6) was the unmerged PR HEAD; this advances to the merge commit so the submodule history matches its remote main. Skipping pre-commit: the hook attributes pre-existing `lint/suspicious/noExplicitAny` warnings in Tooltip.tsx (already on ui/main, untouched by this commit) to the submodule path bump because `packages/ui` matches every path inside the submodule. Submodule typecheck/lint were already validated locally during PR #3's review. Co-Authored-By: Claude Opus 4.7 <[email protected]> --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
useSidebarStateintouseSidebarState.web.ts(localStorage, sync) anduseSidebarState.native.ts(AsyncStorage, async hydrate) with a shared shape inuseSidebarState.ts.useAccessibilityInfolikewise — previously the file lived underplatform/native/but branched onPlatform.OSinside, mixing web (matchMedia) and native (AccessibilityInfo) impls in one file. Now Metro resolves the right one at build time.platform/native/folder and updatesplatform/index.tsto point at the new flat layout.Why
Per the parent repo's platform-safety audit, runtime
Platform.OSchecks for primitives that diverge by platform are noisy in feature code and obscure the actual web/native split. Platform-extension files (.web.ts/.native.ts) let Metro choose at build time — no runtime branch, tree-shaken bundle.Paired with UNI-Construct's platform-safety-audit PR which migrates ~50 feature-code call-sites to a new
@scf/core/utils/platform/*primitive set.Test plan
pnpm -F @scaffald/ui exec tsc --noEmit)🤖 Generated with Claude Code