Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/mobile
Steps to reproduce
Use a checkout with its locked dependencies installed. Run the script below with env -u NODE_ENV sh repro.sh <path-to-that-checkout>. It clones the checkout into a temporary directory at the commit under Version or commit, borrows the checkout's installed node_modules, gives the probe a private HOME, TMPDIR and T3CODE_HOME, and removes the fixture on exit; SOURCE_REF=<fetched ref> reruns the same probe against another revision's source. The embedded probe (probe.cjs) passes each URL through the production shouldHandleAppLink, the static linking configuration built from RootStack, React Navigation's getStateFromPath and restoreDraftLinkState, then renders the registered production screen inside the production GuardedScreenLayout error boundary and clicks Go back when the fallback appears. Native components and connection/data hooks are stubbed; the parser, ID schemas, screen component bodies, boundary, fallback and recovery callback run from production source. It exits 0 when both controls render and all five blank-ID links reach the fallback, so its assertions pin the current defect.
Inputs: the controls t3code://threads/env-1/thread-1/browser and t3code://threads/env-1/thread-1/apps/item-1, then the same URLs with exactly one of the environment, thread or item segments replaced by %20. On a device, the equivalent is opening such a hand-edited t3code:// link; that native path was not run.
Reproduction script: repro.sh (embeds probe.cjs)
#!/bin/sh
# Usage: sh repro.sh /absolute/path/to/dependency-installed/t3code
# Optional SOURCE_REF reruns source from an already-fetched git revision.
set -eu
source_checkout=$(cd "${1:?Pass a dependency-installed t3code checkout}" && pwd)
if [ -n "${SOURCE_REF:-}" ]; then
SOURCE_REF=$(git -C "$source_checkout" rev-parse "$SOURCE_REF")
export SOURCE_REF
fi
fixture=$(mktemp -d "${REPRO_TMP_ROOT:-${TMPDIR:-/tmp}}/mobile-blank-link.XXXXXX")
trap 'rm -rf "$fixture"' EXIT HUP INT TERM
mkdir -p "$fixture/userhome" "$fixture/tmp" "$fixture/t3home"
# A fresh local clone gives the requested baseline, borrowing only the installed pinned dependencies.
git clone -q --shared --no-checkout "$source_checkout" "$fixture/checkout"
git -C "$fixture/checkout" checkout -q --detach d9805b2ca667be7caec8c9035950564ab96704c3
for package in "$source_checkout" "$source_checkout"/apps/* "$source_checkout"/packages/*; do
if [ -d "$package/node_modules" ]; then
relative=${package#"$source_checkout"}
mkdir -p "$fixture/checkout$relative"
ln -s "$package/node_modules" "$fixture/checkout$relative/node_modules"
fi
done
CHECKOUT="$fixture/checkout"
printf 'source revision: %s\n' "${SOURCE_REF:-d9805b2ca667be7caec8c9035950564ab96704c3}"
cat > "$fixture/probe.cjs" <<'PROBE'
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const { createRequire } = require('node:module');
const { pathToFileURL } = require('node:url');
const { execFileSync } = require('node:child_process');
const assert = require('node:assert/strict');
(async () => {
const checkout = process.env.CHECKOUT;
assert(checkout, 'CHECKOUT must name a dependency-installed checkout');
const mobileRequire = createRequire(path.join(checkout, 'apps/mobile/package.json'));
const babel = mobileRequire('@babel/core');
const presetRequire = createRequire(mobileRequire.resolve('babel-preset-expo/package.json'));
const React = mobileRequire('react');
const { JSDOM } = mobileRequire('jsdom');
const dom = new JSDOM('<div id="root"></div>', {url: 'https://example.test'});
global.window = dom.window;
global.document = dom.window.document;
global.IS_REACT_ACT_ENVIRONMENT = true;
const { createRoot } = mobileRequire('react-dom/client');
const contracts = await import(pathToFileURL(path.join(checkout, 'packages/contracts/src/index.ts')));
const Option = await import(pathToFileURL(mobileRequire.resolve('effect/Option')));
const nativeRequire = createRequire(mobileRequire.resolve('@react-navigation/native/package.json'));
const core = nativeRequire('@react-navigation/core');
let goBackCalls = 0;
const nav = {goBack() {goBackCalls++;}, isFocused: () => true, canGoBack: () => true, addListener: () => () => {}};
const native = {
View: ({children}) => React.createElement('div', null, children),
ScrollView: ({children}) => React.createElement('div', null, children),
TextInput: () => null,
Platform: {OS: 'ios', select: x => x.ios ?? x.default},
StyleSheet: {create: x => x},
};
const nullComponent = () => null;
// Stubs supply native/services context; parser, contracts, screen bodies and error boundary
// below are production code, read unchanged and transpiled only for Node execution.
const generic = new Proxy({}, {get: (_target, key) => key === '__esModule' ? true : nullComponent});
const load = (relative, modules = {}, extra = '') => {
const filename = path.join(checkout, relative);
const source = (process.env.SOURCE_REF
? execFileSync('git', ['-C', checkout, 'show', `${process.env.SOURCE_REF}:${relative}`], {encoding: 'utf8'})
: fs.readFileSync(filename, 'utf8')) + extra;
const transformed = babel.transformSync(source, {
filename, babelrc: false, configFile: false,
plugins: [
[presetRequire.resolve('@babel/plugin-transform-typescript'), {isTSX: true, allowDeclareFields: true}],
[presetRequire.resolve('@babel/plugin-transform-react-jsx'), {runtime: 'automatic'}],
presetRequire.resolve('@babel/plugin-transform-modules-commonjs'),
],
}).code;
const module = {exports: {}};
const req = spec => {
if (Object.hasOwn(modules, spec)) return modules[spec];
if (spec === 'react' || spec.startsWith('react/')) return mobileRequire(spec);
if (spec === '@t3tools/contracts') return contracts;
if (spec === 'effect/Option') return Option;
if (spec === 'react-native') return native;
if (spec === '@react-navigation/native') return {...core, useNavigation: () => nav, useIsFocused: () => true};
if (spec === 'react-native-safe-area-context') return {useSafeAreaInsets: () => ({bottom: 0, top: 0, left: 0, right: 0})};
return generic;
};
vm.runInThisContext(`(function(require,module,exports,__DEV__){${transformed}\n})`, {filename})(req, module, module.exports, false);
return module.exports;
};
const browser = load('apps/mobile/src/features/browser/BrowserPreviewRouteScreen.tsx', {
'../../components/ui/SheetHeader': {SheetHeader: () => React.createElement('span', null, 'Browser control')},
'../../components/ui/useBarInset': {useContentTopInset: () => 0},
'../../lib/appState': {useAppForeground: () => true},
'../../state/preview': {useThreadServerBrowserTabs: () => ({tabs: [], loaded: false})},
'../../state/session': {usePreparedConnection: () => Option.none()},
'../settings/appearance/AppearancePreferencesProvider': {useAppearancePreferences: () => ({themeVariables: {}})},
});
const app = load('apps/mobile/src/features/threads/McpAppFullscreenScreen.tsx', {
'../../components/ui/AppBar': {AppBar: () => React.createElement('span', null, 'App control')},
'../../state/orchestration': {orchestrationEnvironment: {turnItem: x => x}},
'../../state/entities': {useThreadShells: () => [], useThreadShell: () => undefined},
'../../state/query': {useEnvironmentQuery: () => ({data: undefined})},
'@t3tools/client-runtime/environment': {scopeThreadRef: (environmentId, threadId) => ({environmentId, threadId})},
});
let observedErrors = 0;
const boundary = load('apps/mobile/src/components/RenderErrorBoundary.tsx', {
'expo-observe': {Observe: {reportError: () => {observedErrors++;}}},
'./ui/AppText': {AppText: ({children}) => React.createElement('span', null, children)},
'./ui/Button': {Button: ({label, onPress}) => React.createElement('button', {onClick: onPress}, label)},
});
const stack = load('apps/mobile/src/Stack.tsx', {
'./features/layout/createWorkspaceStackNavigator': {createWorkspaceStackNavigator: core.createNavigatorFactory(nullComponent)},
'@react-navigation/native-stack': {createNativeStackScreen: core.createScreenFactory()},
'./features/browser/BrowserPreviewRouteScreen': browser,
'./features/threads/McpAppFullscreenScreen': app,
'./components/RenderErrorBoundary': boundary,
'./features/layout/route-options': {pageRoute: x => x, sheetRoute: x => x, modalRoute: x => x, immersiveRoute: x => x},
'./features/layout/workspace-overlay-routes': {registerPresentedRoutes() {}},
}, '\nexport { GuardedScreenLayout };');
const config = {initialRouteName: 'Home', screens: core.createPathConfigForStaticNavigation(stack.RootStack, {initialRouteName: 'Home'})};
const linking = load('apps/mobile/src/lib/appLinking.ts');
const root = createRoot(document.getElementById('root'), {onCaughtError() {}});
const cases = [
['browser control', 't3code://threads/env-1/thread-1/browser', 'ThreadBrowserPreview', false],
['browser blank environment', 't3code://threads/%20/thread-1/browser', 'ThreadBrowserPreview', true],
['browser blank thread', 't3code://threads/env-1/%20/browser', 'ThreadBrowserPreview', true],
['app control', 't3code://threads/env-1/thread-1/apps/item-1', 'ThreadMcpApp', false],
['app blank environment', 't3code://threads/%20/thread-1/apps/item-1', 'ThreadMcpApp', true],
['app blank thread', 't3code://threads/env-1/%20/apps/item-1', 'ThreadMcpApp', true],
['app blank item', 't3code://threads/env-1/thread-1/apps/%20', 'ThreadMcpApp', true],
];
for (const [label, url, name, shouldFail] of cases) {
assert.equal(linking.shouldHandleAppLink(url, true), true);
const relative = url.slice('t3code://'.length);
const parsed = core.getStateFromPath(relative, config);
const restored = linking.restoreDraftLinkState(parsed, relative);
const route = restored.routes.at(-1);
assert.equal(route.name, name);
const Screen = stack.RootStack.config.screens[name].screen;
const before = observedErrors;
await React.act(async () => {
root.render(React.createElement(stack.GuardedScreenLayout, {key: label, route}, React.createElement(Screen, {route})));
});
const text = document.getElementById('root').textContent;
const failed = observedErrors > before;
console.log(JSON.stringify({label, route: route.name, params: route.params, render: failed ? 'caught screen failure' : 'rendered control', text}));
assert.equal(failed, shouldFail);
assert.equal(text.includes("This screen couldn't be displayed"), shouldFail);
assert.equal(text.includes('Go back'), shouldFail);
if (!shouldFail) assert(text.includes(name === 'ThreadBrowserPreview' ? 'Browser control' : 'App control'));
else {
assert(text.includes('Schema validation failed'));
const goBack = [...document.querySelectorAll('button')].find(button => button.textContent === 'Go back');
const beforeGoBack = goBackCalls;
await React.act(async () => goBack.click());
assert.equal(goBackCalls, beforeGoBack + 1);
}
}
await React.act(async () => root.unmount());
dom.window.close();
console.log('PASS: production linking config/parser, both production screen renders, production screen error boundary/fallback and Go back action; 2 valid controls, 5 recoverable blank-ID failures. Native bindings/services were stubbed; no native-process crash claimed.');
})().catch(error => { console.error(error); process.exitCode = 1; });
PROBE
cd "$CHECKOUT/apps/mobile"
env -u NODE_ENV HOME="$fixture/userhome" TMPDIR="$fixture/tmp" T3CODE_HOME="$fixture/t3home" CHECKOUT="$CHECKOUT" node "$fixture/probe.cjs"Expected behavior
A link with a blank required ID should be handled as a missing route, as other mobile routes do, rather than reaching a schema-error screen. Merged PR #16300 made mobile screens treat hand-typed blank deep-link IDs as missing instead of reaching the error screen. The device-preview route on the same threads/<environmentId>/<threadId>/ prefix checks environmentId.trim() and threadId.trim(), returns null and pops the route. Blank IDs stay invalid under the shared non-blank schema, so the expected result is graceful dismissal, not acceptance of a blank ID.
Actual behavior
Summary. A mobile app link to the thread browser preview (t3code://threads/<environmentId>/<threadId>/browser) or the MCP-app fullscreen screen (t3code://threads/<environmentId>/<threadId>/apps/<itemId>) whose environment, thread or item ID segment is blank, for example %20, opens the screen's "This screen couldn't be displayed" fallback with Error: Schema validation failed instead of being treated as a missing route. The fallback is recoverable: its Go back action works, and well-formed links to both screens render. Reach is limited to manually created or edited links; no ordinary in-app or notification producer of blank-ID links was found.
Observed on both tested sources (see Version or commit): both controls render. Each of the five blank-ID links parses into the registered screen with a literal single space as the parameter, the screen throws Schema validation failed during render, and the production boundary shows "This screen couldn't be displayed" with Try again, Copy details and Go back. Clicking Go back called navigation.goBack. This is a recoverable screen error; native app-process termination was not observed. The throwing calls are the ID constructors in BrowserPreviewRouteScreen and McpAppFullscreenScreen. The full output is under Logs or stack traces.
Evidence
- Expected source: PR fix(contracts): trimmed IDs round-trip #16300's description of blank hand-typed IDs as missing, and the blank-parameter check in
apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsxlines 57-75;TrimmedNonEmptyStringinpackages/contracts/src/baseSchemas.tslines 23-29 keeps blank IDs invalid. - Failure source: the reproduction output under Logs or stack traces;
apps/mobile/src/App.tsxlines 108-148 build the linking configuration and parse links,apps/mobile/src/Stack.tsxlines 624-657 register both screens, and the ID constructors inBrowserPreviewRouteScreen.tsxlines 35-45 andMcpAppFullscreenScreen.tsxlines 76-80 run without a blank check. - Evidence provenance: observed
- Local verification: reproduced
- Reproduction completeness: complete
The other post-parse transforms in App.tsx lines 116-122 (settings, prompt, pairing and scheduled-task handling) were read and target other route names; the probe executes shouldHandleAppLink, the parser and restoreDraftLinkState. Internal navigation to both screens passes current branded IDs (ThreadDetailScreen.tsx lines 451-455, McpAppWebView.tsx lines 408-414), and notifications open the base thread route, so no ordinary producer of a blank-ID link was found and real-world frequency is unknown. iOS/Android URL dispatch and native rendering were not run.
Related
Closed, unmerged PR #28782 centralized existing route-parameter parsers but did not touch either screen; it is related, not a fix. Merged PR #16300 added the blank-ID handling for other mobile routes but not these two.
Restoration check
With the same seven inputs, the two controls still render their screens, and each of the five blank-ID links is handled like the device-preview route: the route is dismissed or treated as missing without rendering "This screen couldn't be displayed" or Schema validation failed. The script's current assertions expect the fallback for the blank cases, so they fail once this is fixed.
Impact
Minor bug or occasional failure
Version or commit
d9805b2, rerun from a clean clone. Also reproduced with SOURCE_REF set to upstream main at 4e48d9e, using the same installed dependencies; the two screen modules, appLinking.ts, RenderErrorBoundary.tsx and baseSchemas.ts are unchanged between them.
Environment
macOS on arm64, Node v26.12.1, React/React DOM 19.3.0, React Navigation native 7.5.1 and core 7.24.0. Rendering used jsdom with native components and connection/data hooks stubbed; no native app, simulator, device, server or provider was started.
Logs or stack traces
Output of the script on the baseline commit; the main run printed its source revision followed by the same lines:
{"label":"browser control","route":"ThreadBrowserPreview","params":{"environmentId":"env-1","threadId":"thread-1"},"render":"rendered control","text":"Browser control"}
{"label":"browser blank environment","route":"ThreadBrowserPreview","params":{"environmentId":" ","threadId":"thread-1"},"render":"caught screen failure","text":"This screen couldn't be displayedTry again. If it keeps happening, copy the details for a bug report.Error: Schema validation failedTry againCopy detailsGo back"}
{"label":"browser blank thread","route":"ThreadBrowserPreview","params":{"environmentId":"env-1","threadId":" "},"render":"caught screen failure","text":"This screen couldn't be displayedTry again. If it keeps happening, copy the details for a bug report.Error: Schema validation failedTry againCopy detailsGo back"}
{"label":"app control","route":"ThreadMcpApp","params":{"environmentId":"env-1","threadId":"thread-1","itemId":"item-1"},"render":"rendered control","text":"App control"}
{"label":"app blank environment","route":"ThreadMcpApp","params":{"environmentId":" ","threadId":"thread-1","itemId":"item-1"},"render":"caught screen failure","text":"This screen couldn't be displayedTry again. If it keeps happening, copy the details for a bug report.Error: Schema validation failedTry againCopy detailsGo back"}
{"label":"app blank thread","route":"ThreadMcpApp","params":{"environmentId":"env-1","threadId":" ","itemId":"item-1"},"render":"caught screen failure","text":"This screen couldn't be displayedTry again. If it keeps happening, copy the details for a bug report.Error: Schema validation failedTry againCopy detailsGo back"}
{"label":"app blank item","route":"ThreadMcpApp","params":{"environmentId":"env-1","threadId":"thread-1","itemId":" "},"render":"caught screen failure","text":"This screen couldn't be displayedTry again. If it keeps happening, copy the details for a bug report.Error: Schema validation failedTry againCopy detailsGo back"}
PASS: production linking config/parser, both production screen renders, production screen error boundary/fallback and Go back action; 2 valid controls, 5 recoverable blank-ID failures. Native bindings/services were stubbed; no native-process crash claimed.
Screenshots, recordings, or supporting files
No response
Workaround
Use the fallback's Go back action, then open a well-formed link or navigate to the thread from the app. The Go back callback and well-formed links were exercised in the render harness; native-device interaction was not tested.
Activity