Skip to content

fix(frontend): prevent error when inputRef is undefined#7649

Open
afsuyadi wants to merge 2 commits into
Flagsmith:mainfrom
afsuyadi:fix-sentry-frontend-error
Open

fix(frontend): prevent error when inputRef is undefined#7649
afsuyadi wants to merge 2 commits into
Flagsmith:mainfrom
afsuyadi:fix-sentry-frontend-error

Conversation

@afsuyadi
Copy link
Copy Markdown

Thanks for submitting a PR! Please check the boxes below:

  • [✓] I have read the Contributing Guide.
  • [✓] I have added information to docs/ if required so people know about the feature.
  • [✓] I have filled in the "Changes" section below.
  • [✓] I have filled in the "How did you test this code" section below.

Changes

Contributes to #7537

It's a problem that happens inside useEffect hook. This hook is used to help the page to focus the screen on a certain HTML element using useRef hook, which is assigned to inputRef.

We can see that the n.input is undefined when it's trying to execute method focus, so the inputRef has not been set. To prevent this from happening, I propose an explicit check to verify that:

  1. inputRef.current exists and isn't null
  2. inputRef.current.focus is actually a function before attempting to call it

How did you test this code?

  1. Run both the backend and frontend in my local
  2. User will be prompted to create an account. Click next
  3. User's cursor will be automatically focused on inputting Organization's Name

Video:

Screencast.from.30-05-26.17.40.29.webm

@afsuyadi afsuyadi requested a review from a team as a code owner May 30, 2026 10:44
@afsuyadi afsuyadi requested review from kyle-ssg and removed request for a team May 30, 2026 10:44
@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

@afsuyadi is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the front-end Issue related to the React Front End Dashboard label May 30, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the focus logic in CreateOrganisationPage.tsx to safely check if the focus method exists before calling it. The reviewer suggests using optional chaining (inputRef.current?.focus?.()) as a cleaner, more idiomatic alternative to the verbose if statement and typeof check.

Comment thread frontend/web/components/pages/CreateOrganisationPage.tsx Outdated
@afsuyadi afsuyadi changed the title fix(sentry-frontend): prevent error when inputRef is undefined fix(frontend): prevent error when inputRef is undefined May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants