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(graphql): preserve shared operation documents (#9131)

Peter Chinman74b09e1ae861
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 68823b04a0..7b6e6fdd9a 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -146,6 +146,12 @@ It checks draft blank lines across remounts, that a sent message renders its
lines with the spacing the draft showed, and pending sends on desktop and phone: clear immediately, restore failed sends, and preserve a new draft typed during delivery.
It also pastes a Macro link and Markdown into a code block, which must keep both as literal text.
+Shared GraphQL query metadata has a backend-free desktop and iPhone WebKit regression:
+`bunx playwright test --config src/lib/urql-solid/browser-test/playwright.config.ts`.
+Publish data and metadata atomically. Reconcile result data only; replace
+operation metadata so shared documents,
+cached query text, and operation names remain consistent across query changes.
+
Block formatting passes a forward copy of the selection to Lexical's
`$setBlocksType` so backward selections include their first paragraph and keep
the editor's actual selection direction. The Markdown core browser suite's
diff --git a/apps/web/src/lib/urql-solid/browser-test/documents.browser.e2e.ts b/apps/web/src/lib/urql-solid/browser-test/documents.browser.e2e.ts
new file mode 100644
index 0000000000..301bb63540
--- /dev/null
+++ b/apps/web/src/lib/urql-solid/browser-test/documents.browser.e2e.ts
@@ -0,0 +1,20 @@
+import { expect, test } from '@playwright/test';
+
+test('switching query state preserves reusable GraphQL documents', async ({
+ page,
+}) => {
+ await page.goto('/');
+ await expect(page.getByLabel('Document integrity')).toHaveText(
+ 'Documents preserved'
+ );
+ for (const name of ['Channels', 'Home', 'Channels']) {
+ await page.getByRole('button', { name, exact: true }).click();
+ await expect(page.getByLabel('Active operation')).toHaveText(
+ name === 'Home' ? 'Soup' : 'ChannelListSoup'
+ );
+ await expect(page.getByLabel('Query result')).toHaveText('Loaded');
+ await expect(page.getByLabel('Document integrity')).toHaveText(
+ 'Documents preserved'
+ );
+ }
+});
diff --git a/apps/web/src/lib/urql-solid/browser-test/harness.tsx b/apps/web/src/lib/urql-solid/browser-test/harness.tsx
new file mode 100644
index 0000000000..a236c557b0
--- /dev/null
+++ b/apps/web/src/lib/urql-solid/browser-test/harness.tsx
@@ -0,0 +1,77 @@
+import { createClient, gql, stringifyDocument } from '@urql/core';
+import { getOperationAST, parse, print } from 'graphql';
+import { createSignal } from 'solid-js';
+import { render } from 'solid-js/web';
+import { filter, map, pipe } from 'wonka';
+import { createUrqlQuery } from '../create-urql-query';
+
+const FIRST_DOCUMENT = gql`query Soup { value }`;
+const SECOND_DOCUMENT = gql`query ChannelListSoup { value }`;
+const FIRST_TEXT = print(FIRST_DOCUMENT);
+const SECOND_TEXT = print(SECOND_DOCUMENT);
+const CLIENT = createClient({
+ url: 'https://localhost/graphql',
+ exchanges: [
+ () => (operations) =>
+ pipe(
+ operations,
+ filter((operation) => operation.kind === 'query'),
+ map((operation) => ({
+ operation,
+ data: { value: 'Loaded' },
+ stale: false,
+ hasNext: false,
+ }))
+ ),
+ ],
+});
+
+function Harness() {
+ const [document, setDocument] = createSignal(FIRST_DOCUMENT);
+ const query = createUrqlQuery<{ value: string }, Record<string, never>>(
+ () => ({
+ client: CLIENT,
+ query: document(),
+ variables: {},
+ })
+ );
+ const integrity = () => {
+ // Observe each new result before inspecting the shared ASTs.
+ if (!query.operation) return 'Loading';
+ const valid =
+ print(FIRST_DOCUMENT) === FIRST_TEXT &&
+ print(SECOND_DOCUMENT) === SECOND_TEXT;
+ const textMatchesName = [FIRST_DOCUMENT, SECOND_DOCUMENT].every(
+ (document) => {
+ const name = getOperationAST(document)?.name?.value;
+ return (
+ getOperationAST(parse(stringifyDocument(document)), name) !== null
+ );
+ }
+ );
+ return valid && textMatchesName
+ ? 'Documents preserved'
+ : 'Document corrupted';
+ };
+ return (
+ <main>
+ <button type="button" onClick={() => setDocument(FIRST_DOCUMENT)}>
+ Home
+ </button>
+ <button type="button" onClick={() => setDocument(SECOND_DOCUMENT)}>
+ Channels
+ </button>
+ <output aria-label="Query result">
+ {query.data?.value ?? 'Loading'}
+ </output>
+ <output aria-label="Document integrity">{integrity()}</output>
+ <output aria-label="Active operation">
+ {query.operation && getOperationAST(query.operation.query)?.name?.value}
+ </output>
+ </main>
+ );
+}
+
+const ROOT = document.getElementById('app');
+if (!ROOT) throw new Error('Missing harness root');
+render(() => <Harness />, ROOT);
diff --git a/apps/web/src/lib/urql-solid/browser-test/index.html b/apps/web/src/lib/urql-solid/browser-test/index.html
new file mode 100644
index 0000000000..4eb0220ecb
--- /dev/null
+++ b/apps/web/src/lib/urql-solid/browser-test/index.html
@@ -0,0 +1,5 @@
+<!doctype html>
+<html lang="en">
+ <head><meta charset="utf-8"><title>Shared GraphQL documents regression</title></head>
+ <body><div id="app"></div><script type="module" src="./harness.tsx"></script></body>
+</html>
diff --git a/apps/web/src/lib/urql-solid/browser-test/playwright.config.ts b/apps/web/src/lib/urql-solid/browser-test/playwright.config.ts
new file mode 100644
index 0000000000..1d3e3fcdb5
--- /dev/null
+++ b/apps/web/src/lib/urql-solid/browser-test/playwright.config.ts
@@ -0,0 +1,22 @@
+import { fileURLToPath } from 'node:url';
+import { defineConfig, devices } from '@playwright/test';
+
+const DIRECTORY = fileURLToPath(new URL('.', import.meta.url));
+const WEB_DIRECTORY = fileURLToPath(new URL('../../../../', import.meta.url));
+const PORT = Number(process.env.URQL_BROWSER_PORT ?? 4197);
+export default defineConfig({
+ testDir: DIRECTORY,
+ testMatch: '*.browser.e2e.ts',
+ outputDir: `${DIRECTORY}/test-results`,
+ use: { baseURL: `http://127.0.0.1:${PORT}` },
+ webServer: {
+ command: `bunx vite --config src/lib/urql-solid/browser-test/vite.config.ts --port ${PORT}`,
+ cwd: WEB_DIRECTORY,
+ url: `http://127.0.0.1:${PORT}`,
+ reuseExistingServer: false,
+ },
+ projects: [
+ { name: 'desktop', use: { browserName: 'chromium' } },
+ { name: 'phone', use: { ...devices['iPhone 13'], browserName: 'webkit' } },
+ ],
+});
diff --git a/apps/web/src/lib/urql-solid/browser-test/vite.config.ts b/apps/web/src/lib/urql-solid/browser-test/vite.config.ts
new file mode 100644
index 0000000000..a82ee6a393
--- /dev/null
+++ b/apps/web/src/lib/urql-solid/browser-test/vite.config.ts
@@ -0,0 +1,17 @@
+import { fileURLToPath } from 'node:url';
+import { defineConfig } from 'vite';
+import solid from 'vite-plugin-solid';
+import tsconfigPaths from 'vite-tsconfig-paths';
+
+const DIRECTORY = fileURLToPath(new URL('.', import.meta.url));
+const WEB_DIRECTORY = fileURLToPath(new URL('../../../../', import.meta.url));
+export default defineConfig({
+ root: DIRECTORY,
+ cacheDir: `${DIRECTORY}/.vite`,
+ plugins: [
+ solid(),
+ tsconfigPaths({ projects: [`${WEB_DIRECTORY}/tsconfig.json`] }),
+ ],
+ resolve: { dedupe: ['solid-js'] },
+ server: { host: '127.0.0.1', strictPort: true },
+});
diff --git a/apps/web/src/lib/urql-solid/create-base-query.ts b/apps/web/src/lib/urql-solid/create-base-query.ts
index cbafeaf944..6fe49bd873 100644
--- a/apps/web/src/lib/urql-solid/create-base-query.ts
+++ b/apps/web/src/lib/urql-solid/create-base-query.ts
@@ -1,5 +1,6 @@
import {
type Accessor,
+ batch,
createComputed,
createMemo,
createSignal,
@@ -59,32 +60,37 @@ export function createBaseQuery<
initialObserver.setReference?.(result);
const update = (next: Result): void => {
- untrack(() => {
- const reconciled = { ...next };
- for (const key in reconciled) {
- if (Object.is(previous[key], next[key])) {
- // reconcile unwraps its entire input before comparing it. Existing
- // store proxies let unwrap skip unchanged branches in constant time.
- reconciled[key] = state[key];
- } else if (
- key === 'data' &&
- (containsReactiveStore(next[key]) ||
+ // Effects must see the new data and loading flags in the same update.
+ batch(() =>
+ untrack(() => {
+ const reconciled = { ...next };
+ for (const key in reconciled) {
+ if (Object.is(previous[key], next[key])) {
+ // reconcile unwraps its entire input before comparing it. Existing
+ // store proxies let unwrap skip unchanged branches in constant time.
+ reconciled[key] = state[key];
+ } else if (
+ key !== 'data' ||
+ containsReactiveStore(next[key]) ||
containsReactiveStore(previous[key]) ||
!supportsStoreReconciliation(next[key]) ||
- !supportsStoreReconciliation(previous[key]))
- ) {
- // Preserve store ownership and fields that Solid reconcile skips.
- setState(
- produce((draft) => {
- draft[key] = next[key];
- })
- );
- reconciled[key] = state[key];
+ !supportsStoreReconciliation(previous[key])
+ ) {
+ // Operations contain shared GraphQL documents and cached request
+ // identities. Reconcile only result data; mutating metadata can
+ // change an operation's name without changing its cached query text.
+ setState(
+ produce((draft) => {
+ draft[key] = next[key];
+ })
+ );
+ reconciled[key] = state[key];
+ }
}
- }
- previous = next;
- setState(reconcile(reconciled));
- });
+ previous = next;
+ setState(reconcile(reconciled));
+ })
+ );
};
createComputed(() => {
diff --git a/apps/web/src/lib/urql-solid/create-urql-query.test.tsx b/apps/web/src/lib/urql-solid/create-urql-query.test.tsx
index ac826054ad..297e0dd018 100644
--- a/apps/web/src/lib/urql-solid/create-urql-query.test.tsx
+++ b/apps/web/src/lib/urql-solid/create-urql-query.test.tsx
@@ -2,12 +2,15 @@ import {
type AnyVariables,
type Client,
CombinedError,
+ createRequest,
type GraphQLRequest,
gql,
+ makeOperation,
type Operation,
type OperationContext,
type OperationResult,
} from '@urql/core';
+import { print } from 'graphql';
import {
type Accessor,
createComponent,
@@ -300,6 +303,44 @@ describe('createUrqlQuery reactive state', () => {
expect(fake.executions[3]?.document).toBe(OTHER_DOCUMENT);
});
+ it('preserves shared documents and prior operations when the query changes', () => {
+ const firstDocument = gql`query InitialChannels { channels { id } }`;
+ const secondDocument = gql`query RecentChannels { channels { id name } }`;
+ const firstText = print(firstDocument);
+ const firstOperation = makeOperation(
+ 'query',
+ createRequest<Data, Variables>(firstDocument, { input: 'first' }),
+ { url: 'https://localhost/graphql', requestPolicy: 'cache-first' }
+ );
+ const secondOperation = makeOperation(
+ 'query',
+ createRequest<Data, Variables>(secondDocument, { input: 'first' }),
+ { url: 'https://localhost/graphql', requestPolicy: 'network-only' }
+ );
+ const fake = makeFakeClient();
+ const [document, setDocument] = createSignal(firstDocument);
+ const query = setup(() => ({
+ query: document(),
+ variables: { input: 'first' },
+ client: fake.client,
+ }));
+ fake.executions[0]?.next({
+ data: { value: 'first' },
+ operation: firstOperation,
+ });
+ setDocument(secondDocument);
+ fake.executions[1]?.next({
+ data: { value: 'second' },
+ operation: secondOperation,
+ });
+
+ expect(query.data?.value).toBe('second');
+ expect(query.operation?.query).toEqual(secondDocument);
+ expect(print(firstDocument)).toBe(firstText);
+ expect(firstOperation.context.requestPolicy).toBe('cache-first');
+ expect(firstOperation.query).toBe(firstDocument);
+ });
+
it('disables synchronously, preserves state, and re-enables', () => {
const fake = makeFakeClient();
const [enabled, setEnabled] = createSignal(true);
@@ -464,6 +505,26 @@ describe('createUrqlQuery reactive state', () => {
expect(descriptors).not.toHaveBeenCalledWith(second.nested);
});
+ it('publishes initial data and settled loading state atomically', () => {
+ const fake = makeFakeClient();
+ const snapshots: Array<[string | undefined, boolean]> = [];
+ const dispose = createRoot((rootDispose) => {
+ const query = createUrqlQuery(() => activeOptions(fake.client));
+ createRenderEffect(() => {
+ snapshots.push([query.data?.value, query.isFetching]);
+ });
+ return rootDispose;
+ });
+ disposals.push(dispose);
+
+ fake.executions[0]?.next({ data: { value: 'loaded' } });
+
+ expect(snapshots).toEqual([
+ [undefined, true],
+ ['loaded', false],
+ ]);
+ });
+
it('publishes data and status together without notifying unchanged data consumers', () => {
const fake = makeFakeClient();
const snapshots: Array<[string | undefined, boolean]> = [];
diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.md
index 3293cf1ad8..acdb40ff24 100644
--- a/docs/agent-guide/channels.md
+++ b/docs/agent-guide/channels.md
@@ -43,6 +43,18 @@ the following paragraph leaves that following paragraph unchanged.
The backend-free quote check is documented in the Markdown browser-test README
linked above.
+## Query document ownership
+
+Switch between Home and Channels repeatedly, including after backgrounding the
+native app. Conversation queries must remain reusable: their operation names and
+serialized GraphQL documents must stay consistent. The backend-free desktop and
+iPhone WebKit regression is
+`bunx playwright test --config src/lib/urql-solid/browser-test/playwright.config.ts`
+from `apps/web`.
+
+Data and loading state publish together, so automatic pagination observes the
+new page cursor before deciding whether to request another page.
+
## Empty direct messages
An empty human DM shows the centered conversations illustration and “Say hello”