Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(onboarding): preserve team inputs across query updates (#7592)

teo79cf8f8d2835
diff --git a/apps/web/src/features/auth/create-app-auth-context.ts b/apps/web/src/features/auth/create-app-auth-context.ts
index f52c44cb68..6b0f6fa8be 100644
--- a/apps/web/src/features/auth/create-app-auth-context.ts
+++ b/apps/web/src/features/auth/create-app-auth-context.ts
@@ -10,6 +10,7 @@ import {
invalidateAllAfterLogin,
useUserInfoQuery,
} from '@queries/auth/user-info';
+import { queryReadyGate } from '@queries/gate';
import { detect } from 'detect-browser';
import type { AuthContext, AuthSession } from './context/auth-context';
import {
@@ -29,7 +30,7 @@ export function createAppAuthContext(): AuthContext {
const sendWelcomeEmail = useSendMobileWelcomeEmail();
const session = (): AuthSession => {
- const data = userInfo.isSuccess ? userInfo.data : undefined;
+ const data = queryReadyGate(userInfo) ? userInfo.data : undefined;
// A signed-out visitor's request 401s rather than answering unauthenticated.
const authenticated = deriveIsAuthenticated({
isLoading: userInfo.isLoading,
diff --git a/apps/web/src/features/onboarding/create-app-onboarding-context.ts b/apps/web/src/features/onboarding/create-app-onboarding-context.ts
index 6f596bc438..4acd4f2f91 100644
--- a/apps/web/src/features/onboarding/create-app-onboarding-context.ts
+++ b/apps/web/src/features/onboarding/create-app-onboarding-context.ts
@@ -13,6 +13,7 @@ import { useCompleteTutorialMutation } from '@queries/auth/tutorial';
import { type UserInfoData, useUserInfoQuery } from '@queries/auth/user-info';
import { useContactsQuery } from '@queries/contacts/contacts';
import { invalidateEmailLinks, useEmailLinksQuery } from '@queries/email/link';
+import { queryReadyGate } from '@queries/gate';
import { useGithubStarsQuery } from '@queries/github-stars';
import { useGtmInviteOfferQuery } from '@queries/gtm-invite/links';
import {
@@ -30,11 +31,11 @@ import {
} from '@queries/team/teams';
import { applyWorkspaceAccent } from './apply-workspace-accent';
import type {
- Loadable,
OnboardingContext,
ViewerState,
} from './context/onboarding-context';
import { onboardingCheckoutRequest } from './core/checkout';
+import { loadableQuery } from './queries/loadable-query';
/** How often connected tools re-check while the user is on the tools step. */
const CONNECTED_TOOLS_POLL_MS = 5_000;
@@ -42,14 +43,14 @@ const CONNECTED_TOOLS_POLL_MS = 5_000;
type UserInfoResult = {
isLoading: boolean;
isError: boolean;
- isSuccess: boolean;
+ isPending: boolean;
error: Error | null;
data: UserInfoData | undefined;
};
function toViewerState(result: UserInfoResult): ViewerState {
// Guarded: an unguarded `data` read suspends while the query is pending.
- const data = result.isSuccess ? result.data : undefined;
+ const data = queryReadyGate(result) ? result.data : undefined;
// A signed-out visitor's request 401s rather than answering unauthenticated.
const authenticated = deriveIsAuthenticated({
isLoading: result.isLoading,
@@ -71,17 +72,6 @@ function toViewerState(result: UserInfoResult): ViewerState {
};
}
-/** TanStack status → source availability; data already loaded wins over a background failure. */
-function loadable<T, R>(
- query: { isSuccess: boolean; isError: boolean; data: T | undefined },
- map: (data: T) => R
-): Loadable<R> {
- if (query.isSuccess && query.data !== undefined)
- return { t: 'ready', value: map(query.data) };
- if (query.isError) return { t: 'error' };
- return { t: 'loading' };
-}
-
/** Real queries, mutations, and app services behind the onboarding contract. */
export function createAppOnboardingContext(): OnboardingContext {
const analytics = useAnalytics();
@@ -111,7 +101,7 @@ export function createAppOnboardingContext(): OnboardingContext {
return () =>
query.isPlaceholderData
? { t: 'loading' }
- : loadable(query, (data) => ({
+ : loadableQuery(query, (data) => ({
status: data.row.status === 'completed' ? 'completed' : 'active',
suggestedTeamDomain: data.suggested_team_domain ?? undefined,
}));
@@ -121,7 +111,7 @@ export function createAppOnboardingContext(): OnboardingContext {
const query = useEmailLinksQuery();
return {
accounts: () =>
- loadable(query, (data) =>
+ loadableQuery(query, (data) =>
data.links.map((link) => ({
address: link.email_address,
isPrimary: link.is_primary,
@@ -168,16 +158,18 @@ export function createAppOnboardingContext(): OnboardingContext {
const contacts = useContactsQuery();
return {
teams: () =>
- loadable(teams, (data) => data.map((team) => ({ name: team.name }))),
+ loadableQuery(teams, (data) =>
+ data.map((team) => ({ name: team.name }))
+ ),
invites: () =>
- loadable(invites, (data) =>
+ loadableQuery(invites, (data) =>
(data.invites ?? []).map((invite) => ({
id: invite.id,
invitedBy: idToDisplayName(invite.invited_by),
}))
),
contacts: () =>
- loadable(contacts, (data) => data.contacts.map(idToEmail)),
+ loadableQuery(contacts, (data) => data.contacts.map(idToEmail)),
retry: () => {
void teams.refetch();
void invites.refetch();
@@ -196,7 +188,7 @@ export function createAppOnboardingContext(): OnboardingContext {
createInviteOffer: () => {
const query = useGtmInviteOfferQuery({ enabled: needsOnboarding });
- return () => loadable(query, (offer) => offer ?? null);
+ return () => loadableQuery(query, (offer) => offer ?? null);
},
startCheckout: (tier, terms) =>
checkout.mutateAsync(
@@ -221,7 +213,7 @@ export function createAppOnboardingContext(): OnboardingContext {
applyAccent: applyWorkspaceAccent,
createGithubStars: () => {
const stars = useGithubStarsQuery();
- return () => (stars.isSuccess ? stars.data : undefined);
+ return () => (queryReadyGate(stars) ? stars.data : undefined);
},
track: (event, data) => analytics.track(event, data),
notifyFailure: (message) => toast.failure(message),
diff --git a/apps/web/src/features/onboarding/queries/loadable-query.test.ts b/apps/web/src/features/onboarding/queries/loadable-query.test.ts
new file mode 100644
index 0000000000..28bc063d02
--- /dev/null
+++ b/apps/web/src/features/onboarding/queries/loadable-query.test.ts
@@ -0,0 +1,46 @@
+import { describe, expect, it } from 'vitest';
+import { loadableQuery } from './loadable-query';
+
+describe('onboarding query sources', () => {
+ it('never reads pending data, including disabled and paused queries', () => {
+ const query = {
+ isPending: true,
+ isError: false,
+ get data(): string | undefined {
+ throw new Error('A pending resource read would suspend onboarding');
+ },
+ };
+ expect(loadableQuery(query, (value) => value)).toEqual({ t: 'loading' });
+ });
+
+ it('keeps loaded data available after a failed background refetch', () => {
+ expect(
+ loadableQuery(
+ {
+ isPending: false,
+ isError: true,
+ data: ['[email protected]'],
+ },
+ (data) => data
+ )
+ ).toEqual({ t: 'ready', value: ['[email protected]'] });
+ });
+
+ it('reports a failed first load without inventing data', () => {
+ expect(
+ loadableQuery(
+ { isPending: false, isError: true, data: undefined },
+ (data) => data
+ )
+ ).toEqual({ t: 'error' });
+ });
+
+ it('treats a loaded null offer as ready', () => {
+ expect(
+ loadableQuery(
+ { isPending: false, isError: false, data: null },
+ (data) => data
+ )
+ ).toEqual({ t: 'ready', value: null });
+ });
+});
diff --git a/apps/web/src/features/onboarding/queries/loadable-query.ts b/apps/web/src/features/onboarding/queries/loadable-query.ts
new file mode 100644
index 0000000000..4701fc4983
--- /dev/null
+++ b/apps/web/src/features/onboarding/queries/loadable-query.ts
@@ -0,0 +1,13 @@
+import { queryReadyGate } from '@queries/gate';
+import type { Loadable } from '../context/onboarding-context';
+
+/** Adapt query state to the onboarding contract without suspending the form. */
+export function loadableQuery<T, R>(
+ query: { isPending: boolean; isError: boolean; data: T | undefined },
+ map: (data: T) => R
+): Loadable<R> {
+ // Retained data wins over a background error; pending resources are never read.
+ if (queryReadyGate(query)) return { t: 'ready', value: map(query.data) };
+ if (query.isError) return { t: 'error' };
+ return { t: 'loading' };
+}
diff --git a/apps/web/src/features/onboarding/views/onboarding-flow-view.test.tsx b/apps/web/src/features/onboarding/views/onboarding-flow-view.test.tsx
index 8b5c2a7c4d..3c23bf414a 100644
--- a/apps/web/src/features/onboarding/views/onboarding-flow-view.test.tsx
+++ b/apps/web/src/features/onboarding/views/onboarding-flow-view.test.tsx
@@ -172,6 +172,27 @@ describe('onboarding flow', () => {
);
});
+ it('preserves team inputs and focus when onboarding suggestions refresh', async () => {
+ const { fake } = setup({ resume: 'team' });
+ await heading('Built for teams.');
+ const name = screen.getByDisplayValue('Acme');
+ const email = screen.getByLabelText('Teammate 1 email');
+ fireEvent.input(name, { target: { value: 'My workspace' } });
+ fireEvent.input(email, { target: { value: '[email protected]' } });
+ email.focus();
+
+ fake.update((world) => {
+ world.record.suggestedTeamDomain = 'updated.example.com';
+ world.contacts.push('[email protected]');
+ });
+
+ await waitFor(() => {
+ expect(screen.getByDisplayValue('My workspace')).toBe(name);
+ expect(screen.getByDisplayValue('[email protected]')).toBe(email);
+ expect(document.activeElement).toBe(email);
+ });
+ });
+
it('joins a pending team invite instead of creating a team', async () => {
const { fake } = setup({
resume: 'team',
diff --git a/apps/web/src/features/onboarding/views/team-step.tsx b/apps/web/src/features/onboarding/views/team-step.tsx
index e9c4ba8ac7..002df21084 100644
--- a/apps/web/src/features/onboarding/views/team-step.tsx
+++ b/apps/web/src/features/onboarding/views/team-step.tsx
@@ -1,4 +1,4 @@
-import { Match, Show, Switch } from 'solid-js';
+import { createMemo, Match, Show, Switch } from 'solid-js';
import { ContinueButton, SkipButton } from '../components/controls';
import {
InvitesPanel,
@@ -32,13 +32,17 @@ export function TeamStep(props: {
return viewer.t === 'signed-in' ? viewer.viewer.email : undefined;
};
// Wait for contacts and the domain suggestion so the form mounts once,
- // fully formed — nothing rewrites the user's rows afterwards.
- const seed = () =>
- teamFormSeed({
- record: record(),
- contacts: directory.contacts(),
- ownEmail: ownEmail(),
- });
+ // fully formed. Keep the first settled seed so background refreshes cannot
+ // replace the form, reset edits, or steal focus from an input.
+ const seed = createMemo<TeamFormSeed | undefined>(
+ (previous) =>
+ previous ??
+ teamFormSeed({
+ record: record(),
+ contacts: directory.contacts(),
+ ownEmail: ownEmail(),
+ })
+ );
return (
<TeamSetup>
@@ -71,13 +75,12 @@ export function TeamStep(props: {
<Match when={team.state().t === 'create'}>
<Show
when={seed()}
- keyed
fallback={<TeamStatus message="Finding your teammates…" />}
>
{(ready) => (
<TeamForm
finishing={props.finishing}
- seed={ready}
+ seed={ready()}
ownEmail={ownEmail()}
onContinue={props.onContinue}
onSkip={props.onSkip}
diff --git a/apps/web/src/lib/core/context/user.ts b/apps/web/src/lib/core/context/user.ts
index f3d7f954c6..94c803e1fd 100644
--- a/apps/web/src/lib/core/context/user.ts
+++ b/apps/web/src/lib/core/context/user.ts
@@ -55,7 +55,14 @@ export const [UserContextProvider, useUserContext] =
const isLoading = () => query.isLoading;
- const isAuthenticated = createMemo(() => deriveIsAuthenticated(query));
+ const isAuthenticated = createMemo(() =>
+ deriveIsAuthenticated({
+ isLoading: query.isLoading,
+ isError: query.isError,
+ error: query.error,
+ data: userInfo(),
+ })
+ );
const userId = createMemo(() => userInfo()?.id);
const email = createMemo(() => userInfo()?.email);
diff --git a/apps/web/src/lib/core/email-link/index.ts b/apps/web/src/lib/core/email-link/index.ts
index 116cdafd65..26785ec568 100644
--- a/apps/web/src/lib/core/email-link/index.ts
+++ b/apps/web/src/lib/core/email-link/index.ts
@@ -7,6 +7,7 @@ import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
import { useInitGmailLink } from '@queries/auth';
import { invalidateUserInfo } from '@queries/auth/user-info';
import { invalidateEmailLinks, useEmailLinksQuery } from '@queries/email/link';
+import { queryReadyGate } from '@queries/gate';
import type { ConsentScopes } from '@service-auth/client';
import {
ALREADY_INITIALIZED_CODE,
@@ -30,7 +31,7 @@ const [emailRefetchInterval, setEmailRefetchInterval] = createSignal<
>();
function hasEmailLinks(query: UseQueryResult<ListLinksResponse, Error>) {
- if (!query.data || query.error) {
+ if (!queryReadyGate(query)) {
return false;
}
return query.data.links.length > 0;
diff --git a/apps/web/src/lib/core/pipedream/catalog.ts b/apps/web/src/lib/core/pipedream/catalog.ts
index 362527f6c0..e2b3c2d335 100644
--- a/apps/web/src/lib/core/pipedream/catalog.ts
+++ b/apps/web/src/lib/core/pipedream/catalog.ts
@@ -1,5 +1,6 @@
import { pipedreamAppAvailableInEnv } from '@core/component/AI/constant/mcpServers';
import { toast } from '@core/component/Toast/Toast';
+import { queryReadyGate } from '@queries/gate';
import {
connectPipedreamApp,
usePipedreamCatalogQuery,
@@ -38,7 +39,7 @@ export function createPipedreamCatalogSearch(
const query = usePipedreamCatalogQuery(search);
const entries = (): PipedreamCatalogEntryResponse[] => {
- if (!query.isSuccess) return [];
+ if (!queryReadyGate(query)) return [];
return (query.data?.pages ?? [])
.flatMap((page) => page.servers)
.filter(
diff --git a/apps/web/src/lib/queries/pipedream-connectors.ts b/apps/web/src/lib/queries/pipedream-connectors.ts
index 8511952187..9913727009 100644
--- a/apps/web/src/lib/queries/pipedream-connectors.ts
+++ b/apps/web/src/lib/queries/pipedream-connectors.ts
@@ -1,6 +1,7 @@
import { openPipedreamConnectUI } from '@core/pipedream/connect-ui';
import { ThrownResultError, throwOnErr } from '@core/util/result';
import { queryClient } from '@queries/client';
+import { queryReadyGate } from '@queries/gate';
import {
cognitionApiServiceClient,
PIPEDREAM_DISABLED,
@@ -69,12 +70,12 @@ export function usePipedreamConnectedSlugs(options?: {
const slugs = createMemo<ReadonlySet<string>>(
() =>
new Set(
- (query.isSuccess ? query.data : NO_CONNECTIONS).map(
+ (queryReadyGate(query) ? query.data : NO_CONNECTIONS).map(
(connection) => connection.app_slug
)
)
);
- const ready = () => !query.isPlaceholderData && !query.isPending;
+ const ready = () => !query.isPlaceholderData && queryReadyGate(query);
return { slugs, ready };
}
diff --git a/docs/AGENT_GUIDE/login.md b/docs/AGENT_GUIDE/login.md
index e21dc9ae76..f31beefcd0 100644
--- a/docs/AGENT_GUIDE/login.md
+++ b/docs/AGENT_GUIDE/login.md
@@ -127,6 +127,10 @@ Tools use the same Pipedream catalog and connection UI as Settings. Search, load
more, cancel/retry connection, and confirm connected checks persist on return.
Team setup retains existing membership, invite acceptance, domain suggestions,
and editable invite recipients; submitting the form sends real invitations.
+On the create-team form, type a workspace name and edit a teammate address,
+then allow onboarding/contacts queries to refresh. The same inputs must retain
+their values and focus as suggestions arrive or a background request fails.
+Pending queries must show local loading states without suspending the flow.
Members with an active or trialing license, including a license from their team,
finish directly from the team step without visiting the plan page. The Continue