Skip to content

Conversation

@mirekm
Copy link
Member

@mirekm mirekm commented Dec 4, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 4, 2025 14:09
@mirekm mirekm requested a review from a team as a code owner December 4, 2025 14:09
@changeset-bot
Copy link

changeset-bot bot commented Dec 4, 2025

🦋 Changeset detected

Latest commit: 59b0b21

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

This PR includes changesets to release 1 package
Name Type
saleor-dashboard 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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issues with external authentication buttons in React Strict Mode by converting from a lazy query to a regular query with skip logic and implementing a ref-based guard to prevent double-processing of authentication callbacks.

Key Changes:

  • Replaced useAvailableExternalAuthenticationsLazyQuery with useAvailableExternalAuthenticationsQuery using conditional skip logic
  • Added useRef to prevent double-processing of external auth callbacks in React Strict Mode
  • Removed problematic cleanup logic from useEffect that was clearing localStorage during simulated unmounts

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/auth/views/Login.tsx Converted lazy query to regular query with skip parameter; added ref-based guard for callback processing; removed cleanup logic from useEffect
src/auth/components/LoginPage/LoginPage.test.tsx Improved test structure with helper function; added test cases for edge cases (empty array, undefined); removed mock in favor of actual MemoryRouter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

❌ Patch coverage is 11.76471% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.56%. Comparing base (5373ccd) to head (59b0b21).

Files with missing lines Patch % Lines
src/auth/views/Login.tsx 11.76% 15 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6175    +/-   ##
========================================
  Coverage   39.56%   39.56%            
========================================
  Files        2415     2415            
  Lines       39920    39918     -2     
  Branches     8821     9149   +328     
========================================
+ Hits        15794    15795     +1     
+ Misses      24100    24097     -3     
  Partials       26       26            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI review requested due to automatic review settings December 4, 2025 14:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 82 to 97
useEffect(() => {
const { code, state } = params;
const externalAuthParamsExist = code && state && isCallbackPath;
const externalAuthNotPerformed = !authenticating && !errors.length;

if (externalAuthParamsExist && externalAuthNotPerformed) {
handleExternalAuthentication(code, state);
// Guard against double-processing in React Strict Mode
if (isExternalAuthCallback && externalAuthNotPerformed && !externalAuthProcessedRef.current) {
externalAuthProcessedRef.current = true;
handleExternalAuthentication(code!, state!);
}

return () => {
setRequestedExternalPluginId(null);
setFallbackUri(null);
};
}, []);
}, [isExternalAuthCallback, authenticating, errors.length]);
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The useEffect hook is missing handleExternalAuthentication, code, and state in its dependency array. According to React's exhaustive-deps rule, all values used inside the effect that come from the component scope should be included in the dependency array.

Since handleExternalAuthentication is defined in the component, it should either be:

  1. Added to the dependency array along with code and state (which would require memoizing handleExternalAuthentication with useCallback)
  2. Or moved inside the useEffect to avoid the dependency

The recommended fix is to move the function definition inside the useEffect:

useEffect(() => {
  const externalAuthNotPerformed = !authenticating && !errors.length;

  if (isExternalAuthCallback && externalAuthNotPerformed && !externalAuthProcessedRef.current) {
    externalAuthProcessedRef.current = true;
    
    const handleExternalAuthentication = async (code: string, state: string) => {
      await loginByExternalPlugin!(requestedExternalPluginId, {
        code,
        state,
      });
      setRequestedExternalPluginId(null);
      navigate(fallbackUri);
      setFallbackUri(null);
    };
    
    handleExternalAuthentication(code!, state!);
  }
}, [isExternalAuthCallback, authenticating, errors.length, loginByExternalPlugin, requestedExternalPluginId, setRequestedExternalPluginId, navigate, fallbackUri, setFallbackUri, code, state]);

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +43
// Track if external auth callback has been processed to avoid double-processing in Strict Mode
const externalAuthProcessedRef = useRef(false);
Copy link
Member

Choose a reason for hiding this comment

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

issue: I don't think we should create hacks to work around strict mode, if we have issue there it probably means we have something wrong with our implementation. It's worth checking ESLint warnings.

There's also a possibility we could introduce a bug here, as copilot wrote: https://github.com/saleor/saleor-dashboard/pull/6175/files#r2589250212

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I see it it's not necessarily a hack for React Strict Mode per se. What should we do when component remounts and Apollo has the lazy query in flight?

Copy link
Member Author

Choose a reason for hiding this comment

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

Assuming we can't have that race condition realistically outside of strict mode the ref is indeed unnecessary but what do we do then for the strict mode so it works as expected?

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment was I think already addressed.

Comment on lines +102 to 106
// Guard against double-processing in React Strict Mode
if (isExternalAuthCallback && externalAuthNotPerformed && !externalAuthProcessedRef.current) {
externalAuthProcessedRef.current = true;
handleExternalAuthentication(code!, state!);
}
Copy link
Member

Choose a reason for hiding this comment

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

issue: again we probably have issue somewhere else, we shouldn't write specific fixes to Strict mode

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

3 participants