Skip to content

Fix: Handle Undefined Window in getOrigin to Prevent SSR Errors - #8878

Open
tmdeveloper007 wants to merge 1 commit into
JhaSourav07:mainfrom
tmdeveloper007:fix/8846-get-origin-ssr-guard
Open

Fix: Handle Undefined Window in getOrigin to Prevent SSR Errors#8878
tmdeveloper007 wants to merge 1 commit into
JhaSourav07:mainfrom
tmdeveloper007:fix/8846-get-origin-ssr-guard

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Summary of What Has Been Done

Refactored getOrigin to use an explicit guard for browser context. The window.location.origin access is now isolated with explicit typeof window !== 'undefined' and window != null checks.

Changes Made

  • utils/urls.ts: Refactored getOrigin with explicit browser context guard

Impact it Made

  • Prevents SSR errors during server-side rendering in Next.js
  • Makes the function safer across deployment environments

Closes #8846

Note: Please assign this PR to the tmdeveloper007 account.

@retenta-bot

retenta-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

This pull request addresses the issue of SSR errors by ensuring that the getOrigin function only accesses window.location.origin when the window object is defined. This aligns with previous decisions made to enhance the safety of the function across different deployment environments. Thank you for your contribution!

@retenta-bot retenta-bot Bot changed the title fix : handled undefined window in getOrigin to prevent SSR errors Fix: Handle Undefined Window in getOrigin to Prevent SSR Errors Aug 5, 2026
@Aamod007 Aamod007 added level:beginner Small changes Usually isolated fixes or simple UI/text updates. quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:bug Something isn't working as expected mentor:Aamod007 labels Aug 6, 2026

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great fix for SSR compatibility! Creating a dedicated \�rowserOrigin\ variable with strict checks (\ ypeof window !== 'undefined' && window != null) in \utils/urls.ts\ makes the \getOrigin\ function much safer for server-side environments like Next.js. The logic is clean and easy to follow. Approved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:beginner Small changes Usually isolated fixes or simple UI/text updates. mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix : handle undefined window in getOrigin to prevent SSR errors

2 participants