8000 [package][router] fix: safely access window.location.origin in Sitemap by MohammedAbidNafi · Pull Request #41175 · expo/expo · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@MohammedAbidNafi
Copy link
@MohammedAbidNafi MohammedAbidNafi commented Nov 22, 2025

Why

I was facing the following error:

Simulator Screenshot - iPhone 16 Pro - 2025-11-23 at 00 26 49

This PR fixes the "Render Error" in the Sitemap component where accessing window.location.origin would cause a crash if window or window.location is undefined

How

I modified the SystemInfo function in the Sitemap.tsx file to safely access window.location.origin

Previously, the code directly accessed window.location.origin, which could cause a crash if window or window.location was undefined

Previous code
const locationOrigin = window.location.origin;

I replaced the direct access with a conditional check
const locationOrigin = typeof window !== 'undefined' && window.location ? window.location.origin : null;

This ensures that

  • window exists
  • window.location exists
  • Only then we access origin
  • if either checks fail we default to null, preventing the crash

Test Plan

The reviewer can reproduce the bug by running this in a mobile app
router.navigate('/_sitemap')

  • Manually verified where it no longer crashes and works as expected
  • Ran yarn build in expo-router package and got 0 errors
  • Ran yarn lint ran successfully

Checklist

@github-actions
Copy link
Contributor

Subscribed to pull request

File Patterns Mentions
packages/expo-router/** @EvanBacon, @Ubax, @hassankhan, @kitten

Generated by CodeMention

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Nov 22, 2025
@expo-bot expo-bot added bot: needs changes ExpoBot found things that don't meet our guidelines and removed bot: suggestions ExpoBot has some suggestions labels Nov 22, 2025
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: needs changes ExpoBot found things that don't meet our guidelines labels Nov 22, 2025
@MohammedAbidNafi MohammedAbidNafi changed the title [router] fix: safely access window.location.origin in Sitemap [package][router] fix: safely access window.location.origin in Sitemap Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: passed checks ExpoBot has nothing to complain about

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0