Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/expo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export interface GenerateTypedHelpersOptions {
* @example "/api/uploadthing"
* @example "https://www.example.com/api/uploadthing"
*
* If relative, host will be inferred from either the `EXPO_PUBLIC_SERVER_ORIGIN` environment variable or `ExpoConstants.hostUri`
* If relative, host will be inferred from either the `EXPO_PUBLIC_SERVER_URL` environment variable or `ExpoConstants.hostUri`
*
* @default (process.env.EXPO_PUBLIC_SERVER_ORIGIN ?? ExpoConstants.debuggerHost) + "/api/uploadthing"
* @default (process.env.EXPO_PUBLIC_SERVER_URL ?? ExpoConstants.debuggerHost) + "/api/uploadthing"
Comment on lines +19 to +21

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* If relative, host will be inferred from either the `EXPO_PUBLIC_SERVER_URL` environment variable or `ExpoConstants.hostUri`
*
* @default (process.env.EXPO_PUBLIC_SERVER_ORIGIN ?? ExpoConstants.debuggerHost) + "/api/uploadthing"
* @default (process.env.EXPO_PUBLIC_SERVER_URL ?? ExpoConstants.debuggerHost) + "/api/uploadthing"
* If relative, host will be inferred from either the `EXPO_PUBLIC_SERVER_URL` environment variable or `Constants.expoConfig?.hostUri`
*
* @default (process.env.EXPO_PUBLIC_SERVER_URL ?? Constants.expoConfig?.hostUri) + "/api/uploadthing"

JSDoc comments reference ExpoConstants.debuggerHost but the actual code uses Constants.expoConfig?.hostUri, creating documentation inconsistency.

View Details

Analysis

JSDoc comments reference incorrect ExpoConstants properties

What fails: JSDoc documentation in packages/expo/src/index.ts references non-existent ExpoConstants.debuggerHost and ExpoConstants.hostUri properties, while the actual implementation correctly uses Constants.expoConfig?.hostUri

How to reproduce:

// Documentation claims these exist:
ExpoConstants.debuggerHost    // Does not exist
ExpoConstants.hostUri         // Does not exist

// But actual code uses:
Constants.expoConfig?.hostUri  // This is correct

Result: Documentation inconsistency misleads developers about the correct API usage

Expected: JSDoc should match the actual implementation and reference Constants.expoConfig?.hostUri per Expo Constants API docs - hostUri is only available in expoConfig during development

*/
url?: URL | string;
/**
Expand Down Expand Up @@ -55,17 +55,18 @@ export const generateReactNativeHelpers = <TRouter extends FileRouter>(
let url = new URL("http://localhost:8081/api/uploadthing");
try {
url = new URL(
initOpts?.url ?? "/api/uploadthing",
typeof window.location !== "undefined"
? window.location.origin
: (process.env.EXPO_PUBLIC_SERVER_ORIGIN ?? `http://${debuggerHost}`),
initOpts?.url ?? "/api/uploadthing",
process.env.EXPO_PUBLIC_SERVER_URL ??
(typeof window !== "undefined" && window.location?.origin
? window.location?.origin
: `http://${debuggerHost}`),
);
} catch (err) {
// Can't throw since window.location is undefined in Metro pass
// but may get defined when app mounts.
// eslint-disable-next-line no-console
console.warn(
`Failed to resolve URL from ${initOpts?.url?.toString()} and ${process.env.EXPO_PUBLIC_SERVER_ORIGIN} or ${debuggerHost}. Your application may not work as expected.`,
`Failed to resolve URL from ${initOpts?.url?.toString()} and ${process.env.EXPO_PUBLIC_SERVER_URL} or ${debuggerHost}. Your application may not work as expected.`,
err,
Comment on lines +59 to 70

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Restore support for EXPO_PUBLIC_SERVER_ORIGIN.

This change drops the old env key entirely, so any existing app that already had EXPO_PUBLIC_SERVER_ORIGIN configured (which was required up to now) will silently revert to the window/debuggerHost fallback. In React Native contexts without window (the bug we’re fixing), that means we now end up on http://${debuggerHost}—i.e. broken uploads after upgrading. Please keep the old variable as a fallback (and reflect it in the warning) so existing deployments don’t regress.

-    url = new URL(
-    	initOpts?.url ?? "/api/uploadthing",
-    	process.env.EXPO_PUBLIC_SERVER_URL ??
-    		(typeof window !== "undefined" && window.location?.origin
-    			? window.location?.origin
-    			: `http://${debuggerHost}`),
-    );
+    url = new URL(
+      initOpts?.url ?? "/api/uploadthing",
+      process.env.EXPO_PUBLIC_SERVER_URL ??
+        process.env.EXPO_PUBLIC_SERVER_ORIGIN ??
+        (typeof window !== "undefined" && window.location?.origin
+          ? window.location?.origin
+          : `http://${debuggerHost}`),
+    );
@@
-      `Failed to resolve URL from ${initOpts?.url?.toString()} and ${process.env.EXPO_PUBLIC_SERVER_URL} or ${debuggerHost}. Your application may not work as expected.`,
+      `Failed to resolve URL from ${initOpts?.url?.toString()} and ${
+        process.env.EXPO_PUBLIC_SERVER_URL ?? process.env.EXPO_PUBLIC_SERVER_ORIGIN
+      } or ${debuggerHost}. Your application may not work as expected.`,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
process.env.EXPO_PUBLIC_SERVER_URL ??
(typeof window !== "undefined" && window.location?.origin
? window.location?.origin
: `http://${debuggerHost}`),
);
} catch (err) {
// Can't throw since window.location is undefined in Metro pass
// but may get defined when app mounts.
// eslint-disable-next-line no-console
console.warn(
`Failed to resolve URL from ${initOpts?.url?.toString()} and ${process.env.EXPO_PUBLIC_SERVER_ORIGIN} or ${debuggerHost}. Your application may not work as expected.`,
`Failed to resolve URL from ${initOpts?.url?.toString()} and ${process.env.EXPO_PUBLIC_SERVER_URL} or ${debuggerHost}. Your application may not work as expected.`,
err,
url = new URL(
initOpts?.url ?? "/api/uploadthing",
process.env.EXPO_PUBLIC_SERVER_URL ??
process.env.EXPO_PUBLIC_SERVER_ORIGIN ??
(typeof window !== "undefined" && window.location?.origin
? window.location?.origin
: `http://${debuggerHost}`),
);
} catch (err) {
// Can't throw since window.location is undefined in Metro pass
// but may get defined when app mounts.
// eslint-disable-next-line no-console
console.warn(
`Failed to resolve URL from ${initOpts?.url?.toString()} and ${
process.env.EXPO_PUBLIC_SERVER_URL ?? process.env.EXPO_PUBLIC_SERVER_ORIGIN
} or ${debuggerHost}. Your application may not work as expected.`,
err,
🤖 Prompt for AI Agents
In packages/expo/src/index.ts around lines 59 to 70, the code removed fallback
support for the legacy EXPO_PUBLIC_SERVER_ORIGIN env var causing RN contexts
without window to fall back to http://${debuggerHost}; restore support by
checking process.env.EXPO_PUBLIC_SERVER_URL first, then
process.env.EXPO_PUBLIC_SERVER_ORIGIN, then the window.location origin fallback
and finally http://${debuggerHost}; update the warning logged in the catch to
mention EXPO_PUBLIC_SERVER_ORIGIN alongside EXPO_PUBLIC_SERVER_URL and
debuggerHost so existing deployments are not regressed and users see the correct
env variables referenced.

);
}
Expand Down
Loading