Repository navigation
feat(mobile): native shell mode — useNativeHost, typed bridge calls, and the Console wired to the mobile shell - #29140
Conversation
…Console router wiring Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jT77n7bRx8GRbrHKo7
…section; changeset Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jT77n7bRx8GRbrHKo7
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jT77n7bRx8GRbrHKo7
|
domain:ui#4 · zhuangjianguo · session_01QsR2jR7ZFkpqmm4U8S1f9y Contract reviewServed-tier: Face: declaration. The PR body and the changeset declare ① Derived judgments
② Semver levelBoth changeset entries are ③ Boundary flags
Implemented-by: VERDICT: PASS Generated by Claude Code |
|
domain:ui#4 · zhuangjianguo · session_01QsR2jR7ZFkpqmm4U8S1f9y 席位核对 · ACCEPT · 2026-11-02T08:43ZHead-sha:
Generated by Claude Code |
Consumer acceptance (mobile shell side)Verdict: accepted, with follow-ups. No must-fix drift. Checked against objectstack-ai/mobile Contract parity, item by item:
The safe area is not padded twice: the Console adds no padding, and the shell pads natively. Follow-ups filed:
Generated by Claude Code |
Requested by Steedos · project thread
Fixes #29039
Clause-②: yes (widening) —
@object-ui/mobileis published and gains new exports; the seat writes the TIER_DEFAULT contract review.Metadata-protocol: none
维护者速读
window.ObjectStackNative)。@object-ui/mobile新增useNativeHost()、桥的类型与五个不抛错的调用封装;Console 在路由层向外壳发送ready()(每次页面加载一次,首个路由渲染之后)与routeChanged(route)(每次 SPA 导航一次),并接住外壳的objectstack-native:navigate事件用自己的路由跳转、不再整页重载。ui/packages/mobile/src/useNativeHost.ts(延迟检测的复查点、路由接线、导航事件只接受站内路径);②ui/packages/mobile/src/nativeHost.ts(桥类型、has()能力检测、NativeCallResult);③ui/apps/console/src/App.tsx的NativeShellRouting。pnpm --dir ui exec vitest run packages/mobile/src/__tests__/nativeHost.test.tsx apps/console/src/__tests__/App.nativeShellMode-29039.test.tsx,预期 44 个测试全绿(外壳模式 ready 只发一次、导航事件被接住、没有全局时一切照旧)。What changes
The ObjectStack mobile shell (objectstack-ai/mobile#144) hosts this Console in a WebView and injects
window.ObjectStackNative. The bridge contract is the mobile repository'sdocs/HYBRID-SHELL.md, section "Native bridge" (read at mobile PR 144 head443207c).@object-ui/mobile(new exports only):ObjectStackNativetypes exactly the contract's members:version,platform,appVersion,capabilities,safeArea,has(capability), the callsgetPushToken,haptic,openExternal,navigate,resetServer(each a Promise), and the eventsready()androuteChanged(route). Nothing else is typed. Supporting types:NativeHapticKind,NativePushToken,NativeSafeArea,NativeHostMethod,NativeCallResult.getNativeHost()reads the global at call time and returns it, ornull.useNativeHost()is the React form.useNativeHost()reads the global at render time (useSyncExternalStore), re-reads it once on mount, and, only while no bridge is present, re-checks atDOMContentLoaded(if the document is still loading), at the windowloadevent, and at 100 ms, 500 ms and 2000 ms afterload. The timed re-checks exist because the shell guarantees the bridge on Android only by evaluating its bootstrap again after the page has loaded (react-native-webviewinjectedJavaScript), which can land just afterloadfires. A bridge that appears at any of those points re-renders every caller with it. Without the global the hook returnsnulland nothing else happens.nativeGetPushToken(),nativeHaptic(kind),nativeOpenExternal(url),nativeNavigate(route),nativeResetServer(). Each checkshas(method)(capability names equal method names in the contract) and that the method exists, then calls it. Each resolves aNativeCallResult:{ status: 'unavailable' }(no shell, no capability, no method, or ahas()that throws),{ status: 'ok', value }, or{ status: 'failed', code, message }when the shell rejects the call (its errorcode:unknown_method,bad_args,failed). The wrappers carry anativeprefix so the package entry does not export a barenavigate.postNativeReady()posts at most once per page load.postNativeRouteChanged(route)does not post a route equal to the one it posted last.useNativeHostRouting({ route, navigate })is the router wiring:ready()after the first commit (or as soon as a late bridge appears),routeChangedonce per route change, and the navigate-event listener below. Outside the shell it installs nothing.Console wiring (
ui/apps/console/src/App.tsx,main.tsx):NativeShellRoutingrenders beside theRouteselement insideConsoleShell(so inside its Suspense boundary) under theBrowserRouter. Its first effect therefore runs once the first route has committed, and that is whenready()is posted, not at boot. The route it posts is the router location'spathname + search + hash, which react-router already gives without the basename; the shell's ownrouteFromConsoleUrlkeeps query and fragment too, so the route the shell recovers to is the full one.objectstack-native:navigate, moves its own router todetail.route, and callspreventDefault(), so a notification tap does not reload the bundle. Per the seat's ruling,preventDefault()is called only after the route is accepted, and only an in-app path is accepted: a string that starts with exactly one/, with no backslash and no control character (//host,https:,/+ backslash +host, a relative path, an empty string or a non-string are left alone, so the shell'slocation.assignfallback runs). The navigation postsrouteChangedonce, through the same route-change effect. Outside shell mode the listener is not installed.data-os-native-shell="ios|android", so a stylesheet can tell shell mode apart. Nothing reads it yet.Shell-mode chrome (each element hidden, with the reason):
main.tsxremoves the staticlink rel=manifestfromindex.htmland does not inject the branded blob manifest. The app is installed natively there, so an install manifest has nothing to offer. Read after the boot round-trips; a bridge that lands even later only leaves the manifest in place, which a WebView never acts on.hidden md:flex). No new layout.Safe area: a measured departure from the card's Ask 2 ("pads with the
--os-native-safe-*variables"), ruled by the seat. The shell already pads its WebView:components/shell/ConsoleWebView.tsxat mobile443207cwraps the WebView in a View withpaddingTop: insets.top, paddingBottom: insets.bottom, unconditionally. Padding again in the Console would double the top and bottom insets. So the shell stays the single safe-area owner and the Console adds no padding in shell mode. The insets stay readable (--os-native-safe-*,useNativeHost()?.safeArea) for a later surface that opts in.No spec change, no metadata key, no new gate.
ui/packages/app-shell/src/layout/**is not touched.Tests
ui/packages/mobile/src/__tests__/nativeHost.test.tsx(40 tests): detection (absent, present, non-object global); late injection afterload(timed re-check), atDOMContentLoaded, atload, and the control that staysnullthrough every re-check; every wrapper resolvesunavailablewithout a bridge, whenhas()says no (and the method is never called), and when the method is missing;okwith the value and the forwarded argument;failedwith the shell's code; a throwinghas();readyonce per page load;routeChangedonce per route;useNativeHostRoutingunder StrictMode (oneready, one post per route), a late bridge receivingreadyand the current route, the navigate event (in-app route cancelled and routed; six non-app shapes left alone), no listener outside shell mode, listener removed on unmount.ui/apps/console/src/__tests__/App.nativeShellMode-29039.test.tsx(4 tests), the realAppunder its realBrowserRouterwith the pages stubbed as inApp.docsPortalLazy.test.tsx: with a fake bridge installed before render,readyarrives once and only after the first route's page is on screen, thenrouteChanged('/login'), and the root carriesdata-os-native-shell; the navigate event moves the router by a history push (no document load) and posts the new route once; a//hostroute is left to the shell; control without the global: nothing posted, nothing marked, the event not cancelled.Ablations (each through
scripts/ablation-replace.mjs, mutation landed by anchor count and blob hash, file restored byte-identical by hash, underos-verify-lock), run on the 44 tests above:watchForLateInjectionreturns at once): 4 red, the three late-injection cases and the late-bridge routing case;readyPostedonce-guard removed: 2 red;event.preventDefault()removed from the navigate listener: 2 red (mobile and console);has()+ method check reduced to "bridge present": 11 red.Acceptance notes
__events=ready@/login,route:/login(ready posted once, after 19 elements had rendered under the root); root attributedata-os-native-shell="ios"; no manifest link; body padding0px. Dispatchingobjectstack-native:navigatewith/forgot-password:defaultPreventedtrue, the page moved to/forgot-passwordwith the same boot id (no reload), androute:/forgot-passwordwas posted once./login.load(the dev server'sloadfired at about 7.4 s) still receivedreadyandroute:/login, and the attribute was set.docs/HYBRID-SHELL.md"Console-side integration" says the Console should "pad with the safe-area variables", while the shell pads its WebView unconditionally (ConsoleWebView.tsxat443207c). One of the two has to change before a Console that pads could ship; this PR follows the shell's behaviour.nativeGetPushToken()is ready for it.Verification
All at head
1205cf10(this branch withorigin/main5d3667e2merged in; the merge broughtpackages/speccontract files and a@object-ui/componentsdata-table change, nothing underui/packages/mobileor the console files touched here), after rebuilding the console's dependency closure:pnpm exec vitest run packages/mobile/plus everyapps/console/src/__tests__/App.*.test.tsxand the two other console suites that renderApp(i18nAfterSignIn-12034,internalFormShell), fromui/,--maxWorkers=2, underos-verify-lock: 14 / 14 files, 113 / 113 tests.pnpm --dir ui exec vitest run scripts/: 169 files passed, 2 skipped; 4900 tests passed, 2 skipped.turbo run type-check --filter=@object-ui/mobile --filter=@object-ui/console: 72 / 72 tasks, exit 0.eslinton every touched source and test file: 0 problems.pnpm --dir ui run check:new-line-citations: 0 new citations.node scripts/pm/dispatch-gates.mjs --commands, 34 commands,check-sdui-manifestamong them): 34 / 34 exit 0, reconciled by--ran(34 derived, 34 run, 0 NOT-MEASURED).check-changeset-no-major.mjs --base origin/mainwith this body asGITHUB_EVENT_PATH, andcheck-adr-0087-registration,check-closing-keyword-parityandcheck-partof-closing-keywordon this body: exit 0.Human Minimum
packages/specholds no runtime logic. (not touched)pnpm lintpasses. (eslint on every touched file: 0 problems; the repo-wide run is CI's)main, one pull request.packages/spectouched: not touched.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01QsR2jT77n7bRx8GRbrHKo7
Generated by Claude Code