Skip to content

Conversation

@HamzaNa1
Copy link

@HamzaNa1 HamzaNa1 commented Sep 25, 2025

This fixes #1238

I updated the name of the env variable from EXPO_PUBLIC_SERVER_ORIGIN to EXPO_PUBLIC_SERVER_URL since that is the name the docs mentions

Previously the code checked if window.location is defined, which threw an error because window did not exist, this caused it to fallback to the default URL without checking the env variable

The new code will check if the env variable FIRST and use it if it exists, then check safely for the window and then for the debuggerHost

Summary by CodeRabbit

  • Bug Fixes

    • Improved server URL resolution to safely prefer the browser origin when available and reliably fall back to the debugger host when needed (avoids errors when a browser environment is absent).
  • Chores

    • Replaced EXPO_PUBLIC_SERVER_ORIGIN with EXPO_PUBLIC_SERVER_URL for deriving the app’s server URL.
    • Updated default resolution and runtime warnings to reference the new variable and clarify configuration expectations.

@changeset-bot
Copy link

changeset-bot bot commented Sep 25, 2025

🦋 Changeset detected

Latest commit: 3f65cee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@uploadthing/expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Sep 25, 2025

@HamzaNa1 is attempting to deploy a commit to the Ping Labs Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Walkthrough

Replaces use of EXPO_PUBLIC_SERVER_ORIGIN with EXPO_PUBLIC_SERVER_URL and updates URL resolution to prefer EXPO_PUBLIC_SERVER_URL, then window.location.origin (when available), then http://{debuggerHost}. Adjusts warning message accordingly. No exported/public API changes.

Changes

Cohort / File(s) Summary
Expo URL resolution
packages/expo/src/index.ts
Switched env var from EXPO_PUBLIC_SERVER_ORIGIN to EXPO_PUBLIC_SERVER_URL; updated URL construction fallback order (env → window.location.origin → http://{debuggerHost}); revised warning message text; minor structural alignment in URL construction.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App
  participant ExpoPkg as uploadthing/expo
  participant Env as process.env
  participant Window as window.location
  participant Debugger as debuggerHost

  App->>ExpoPkg: generateReactNativeHelpers(initOpts)
  Note over ExpoPkg: Build base URL
  ExpoPkg->>Env: Read EXPO_PUBLIC_SERVER_URL
  alt EXPO_PUBLIC_SERVER_URL set
    ExpoPkg->>ExpoPkg: Use env URL (absolute or resolve relative)
  else not set
    ExpoPkg->>Window: Check window.location.origin
    alt window available
      ExpoPkg->>ExpoPkg: Use window.location.origin
    else no window
      ExpoPkg->>Debugger: Use http://{debuggerHost}
    end
  end
  ExpoPkg-->>App: Resolved URL (or warn on failure)
  Note right of ExpoPkg: Warning references EXPO_PUBLIC_SERVER_URL
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The title “fix: url creation” indicates a fix related to URL construction but is overly generic and does not clearly convey the primary changes around renaming the environment variable and updating the URL resolution logic. It only partially reflects the scope of the PR and may not immediately inform reviewers or future readers of the key modifications. Therefore, it is inconclusive whether this title sufficiently captures the main change. Consider updating the title to explicitly reference the environment variable rename and the updated URL resolution logic, for example: “fix: use EXPO_PUBLIC_SERVER_URL and update URL fallback logic”.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues Check ✅ Passed The changes rename the environment variable to EXPO_PUBLIC_SERVER_URL, update the URL resolution order to check the env variable before safely handling window availability, and adjust the warning message accordingly, fully addressing the coding requirements outlined in issue #1238.
Out of Scope Changes Check ✅ Passed All modifications are confined to the URL construction logic in packages/expo/src/index.ts, directly targeting the env variable rename and resolution flow described in the linked issue with no unrelated or extraneous changes.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel
Copy link

vercel bot commented Sep 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs-uploadthing Ready Ready Preview Comment Oct 16, 2025 0:19am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
legacy-docs-uploadthing Ignored Ignored Oct 16, 2025 0:19am

@HamzaNa1 HamzaNa1 changed the title fix url creation fix: url creation Sep 25, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18f98a7 and 3320270.

📒 Files selected for processing (1)
  • packages/expo/src/index.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Vercel Agent Review

Comment on lines +59 to 70
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,
Copy link
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.

@vercel vercel bot requested a deployment to Preview – docs-uploadthing October 16, 2025 00:19 Abandoned
@vercel vercel bot requested a deployment to Preview – docs-uploadthing October 16, 2025 00:19 Abandoned
@vercel vercel bot requested a deployment to Preview – docs-uploadthing October 16, 2025 00:19 Abandoned
@vercel vercel bot requested a deployment to Preview – docs-uploadthing October 16, 2025 00:19 Abandoned
@vercel vercel bot requested a deployment to Preview – docs-uploadthing October 16, 2025 00:19 Abandoned
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.changeset/tough-files-leave.md (1)

5-5: Tighten up the sentence for readability.

The run-on sentence makes the changeset harder to scan. Please break it into shorter sentences or add proper punctuation so the timeline of fallbacks is clearer.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3320270 and 3f65cee.

📒 Files selected for processing (1)
  • .changeset/tough-files-leave.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Vercel Agent Review

@markflorkowski
Copy link
Collaborator

Update examples and turbo.json.

Keep old (incorrect) variable as a potential fallback to prevent issues for anyone who worked around this previously

Comment on lines +19 to +21
* 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"
Copy link

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

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.

[bug]: uploadthing/expo does not read the env vairable correctly

2 participants