Skip to content

Conversation

@mhamann
Copy link
Contributor

@mhamann mhamann commented Jan 22, 2026

Summary by Sourcery

Refine authentication state synchronization between client and server cookies and introduce API versioning configuration for the Hub script injector.

Bug Fixes:

  • Ensure RowndServerStateSync distinguishes between initial load, sign-in, sign-out, and token refresh to apply the correct cookie sync and reload behavior.

Enhancements:

  • Track initialization state in RowndServerStateSync to perform a one-time, reload-free cookie sync when a token exists on first load.
  • Add support for an apiVersion configuration in HubScriptInjector with a default SDK API version and propagate it into the Hub configuration.
  • Extend RowndProvider props to accept an apiVersion option for controlling Hub feature behavior.

Tests:

  • Expand RowndServerStateSync tests to cover initial load, sign-in, sign-out, token refresh, and no-change scenarios, including correct use of reload callbacks.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 22, 2026

Reviewer's Guide

Refines Rownd server state synchronization behavior for sign-in/sign-out vs token refresh and introduces an explicit, defaulted Hub API version that propagates from the Rownd provider into the Hub script injector config.

Sequence diagram for RowndServerStateSync initial load behavior

sequenceDiagram
  participant RowndServerStateSync
  participant useRownd
  participant cookieSignIn

  RowndServerStateSync->>useRownd: read access_token, is_initializing
  useRownd-->>RowndServerStateSync: access_token, is_initializing

  alt is_initializing is true
    RowndServerStateSync->>RowndServerStateSync: return early (no sync)
  else is_initializing is false and hasInitialized is false
    RowndServerStateSync->>RowndServerStateSync: set hasInitialized to true
    RowndServerStateSync->>RowndServerStateSync: set prevAccessToken to access_token
    alt access_token exists on initial load
      RowndServerStateSync->>cookieSignIn: cookieSignIn()
    else no access_token on initial load
      RowndServerStateSync->>RowndServerStateSync: do nothing
    end
  end
Loading

Sequence diagram for RowndServerStateSync sign-in, refresh, and sign-out

sequenceDiagram
  participant RowndServerStateSync
  participant useRownd
  participant cookieSignIn
  participant cookieSignOut
  participant Window

  RowndServerStateSync->>useRownd: read access_token, is_initializing
  useRownd-->>RowndServerStateSync: access_token, is_initializing

  RowndServerStateSync->>RowndServerStateSync: compute wasSignedOut, isSigningIn, isSigningOut, isTokenRefresh
  RowndServerStateSync->>RowndServerStateSync: prevAccessToken = access_token

  alt isSigningIn (null -> token)
    RowndServerStateSync->>cookieSignIn: cookieSignIn(reloadCallback)
    activate cookieSignIn
    cookieSignIn-->>RowndServerStateSync: invokes reloadCallback
    RowndServerStateSync->>Window: window.location.reload()
  else isTokenRefresh (token -> different token)
    RowndServerStateSync->>cookieSignIn: cookieSignIn()
  else isSigningOut (token -> null)
    RowndServerStateSync->>cookieSignOut: cookieSignOut(reloadCallback)
    activate cookieSignOut
    cookieSignOut-->>RowndServerStateSync: invokes reloadCallback
    RowndServerStateSync->>Window: window.location.reload()
  else no change (same token)
    RowndServerStateSync->>RowndServerStateSync: no cookie actions
  end
Loading

Class diagram for RowndProvider and HubScriptInjector API versioning

classDiagram
  class RowndProviderProps {
    string appKey
    string~optional~ hubUrlOverride
    string~optional~ postRegistrationUrl
    string~optional~ postSignOutRedirect
    string~optional~ apiVersion
    ReactNode children
  }

  class HubScriptInjectorProps {
    string appKey
    function stateListener
    string~optional~ hubUrlOverride
    string~optional~ locationHash
    string~optional~ apiVersion
  }

  class HubScriptInjector {
    - string DEFAULT_API_VERSION
    + HubScriptInjector(props)
    + setConfigValue(key, value)
  }

  class WindowConfig {
    any[] _rphConfig
  }

  RowndProviderProps <.. HubScriptInjectorProps : passes props
  HubScriptInjectorProps --> HubScriptInjector : used_by
  HubScriptInjector --> WindowConfig : pushes setApiVersion

  HubScriptInjector : useEffect(appKey, stateListener, locationHash, hubUrlOverride, apiVersion, rest)
  HubScriptInjector : setConfigValue(setAppKey, appKey)
  HubScriptInjector : setConfigValue(setStateListener, stateListener)
  HubScriptInjector : setConfigValue(setLocationHash, locationHash)
  HubScriptInjector : setConfigValue(setApiVersion, apiVersion)
  HubScriptInjector : injects hubUrlOverride or default URL
  WindowConfig : _rphConfig.push([setApiVersion, apiVersion])
Loading

File-Level Changes

Change Details Files
Adjust RowndServerStateSync to distinguish initial load, sign-in, sign-out, and token refresh, changing when cookies are synced and when reloads occur, and expand tests to cover these scenarios including proper window.location.reload mocking.
  • Introduce hasInitialized ref to separate first post-initialization render from subsequent state transitions.
  • On initial non-initializing render, cache current access token and, if present, call cookieSignIn without a reload callback.
  • Refactor effect logic to derive isSigningIn, isSigningOut, and isTokenRefresh booleans from previous and current access tokens.
  • On sign-in, call cookieSignIn with a reload callback; on token refresh, call cookieSignIn without reload; on sign-out, call cookieSignOut with reload.
  • Restructure RowndServerStateSync tests into scenario-based describe blocks for initial load, sign-in, token refresh, sign-out, and no-change, and fix mockReload scoping so it can be asserted across tests.
src/next/client/components/RowndServerStateSync.tsx
src/next/client/components/RowndServerStateSync.test.tsx
Introduce and propagate an explicit Hub API version configuration with a default date-based version, wiring it into HubScriptInjector config updates and RowndProvider props.
  • Add DEFAULT_API_VERSION constant and optional apiVersion prop to HubScriptInjector, defaulting to the constant.
  • Push the apiVersion into the global _rphConfig via setConfigValue('setApiVersion', apiVersion).
  • Include apiVersion in the HubScriptInjector effect dependency array so config updates when the version changes.
  • Extend RowndProviderProps to accept an optional apiVersion with documentation describing version semantics and opting out of new behaviors.
  • Add an .npmignore file to control which files are published to npm (contents currently empty in diff).
src/context/HubScriptInjector/HubScriptInjector.tsx
src/context/RowndContext.tsx
.npmignore

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions
Copy link

size-limit report 📦

Path Size
dist/main.js 2.34 KB (+1.57% 🔺)
dist/next.js 20.89 KB (+0.39% 🔺)
dist/remix.js 20.78 KB (+0.18% 🔺)

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The hasInitialized ref in RowndServerStateSync never resets, so if the app key or auth context changes while the component remains mounted, the "initial load" branch will never run again; consider tying that initialization state to a stable key (e.g., app key or user/session id) so it can re-run when the underlying auth context changes.
  • The hard-coded DEFAULT_API_VERSION string in HubScriptInjector may drift from the actual SDK version over time; consider sourcing this from a single version/config constant (or package metadata) so future updates do not require manual date changes in multiple places.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `hasInitialized` ref in `RowndServerStateSync` never resets, so if the app key or auth context changes while the component remains mounted, the "initial load" branch will never run again; consider tying that initialization state to a stable key (e.g., app key or user/session id) so it can re-run when the underlying auth context changes.
- The hard-coded `DEFAULT_API_VERSION` string in `HubScriptInjector` may drift from the actual SDK version over time; consider sourcing this from a single version/config constant (or package metadata) so future updates do not require manual date changes in multiple places.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@mhamann mhamann changed the title Fix auth handling fix(auth): token refresh handling issues Jan 22, 2026
@mhamann mhamann merged commit 11fa1b0 into main Jan 22, 2026
11 of 12 checks passed
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.

2 participants