@copilotkit/react-textarea 1.78.0 → 1.79.1-canary.1792034358

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/react-textarea",
3
- "version": "1.78.0",
3
+ "version": "1.79.1-canary.1792034358",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -41,6 +41,9 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
+ "@copilotkit/react-core": "1.79.1-canary.1792034358",
45
+ "@copilotkit/runtime-client-gql": "1.79.1-canary.1792034358",
46
+ "@copilotkit/shared": "1.79.1-canary.1792034358",
44
47
  "@emotion/css": "^11.11.2",
45
48
  "@emotion/react": "^11.11.1",
46
49
  "@emotion/styled": "^11.11.0",
@@ -58,10 +61,7 @@
58
61
  "slate": "^0.94.1",
59
62
  "slate-history": "^0.93.0",
60
63
  "slate-react": "^0.98.1",
61
- "tailwind-merge": "^1.13.2",
62
- "@copilotkit/react-core": "1.78.0",
63
- "@copilotkit/runtime-client-gql": "1.78.0",
64
- "@copilotkit/shared": "1.78.0"
64
+ "tailwind-merge": "^1.13.2"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/lodash.merge": "^4.6.7",
@@ -78,8 +78,8 @@
78
78
  "tsdown": "^0.20.3",
79
79
  "typescript": "^5.2.3",
80
80
  "vitest": "^3.2.4",
81
- "tailwind-config": "1.4.12",
82
- "tsconfig": "1.4.12"
81
+ "tsconfig": "1.4.12",
82
+ "tailwind-config": "1.4.12"
83
83
  },
84
84
  "peerDependencies": {
85
85
  "react": "^18 || ^19 || ^19.0.0-rc",
@@ -0,0 +1,71 @@
1
+ /**
2
+ * #1937: `useMakeStandardAutosuggestionFunction` used to read
3
+ * `copilotApiConfig.headers` directly in its render body (building a
4
+ * `headers` local that was itself dead — the actual GraphQL request is
5
+ * commented out, and `runtimeClient` is a stub; that local's only mention
6
+ * was building it). With an async `headers` builder on `<CopilotKit>`
7
+ * (`packages/react-core`'s v1 wrapper, which `CopilotTextarea` mounts under
8
+ * — see `copilot-textarea.tsx`), that render-time read called the builder
9
+ * on every render of `CopilotTextarea`. The dead `headers` local has been
10
+ * deleted; this test proves the hook's render body never touches
11
+ * `copilotApiConfig.headers` at all, so mounting (and re-rendering) it under
12
+ * an async builder never invokes that builder.
13
+ *
14
+ * react-textarea has no jsdom / `@testing-library/react` setup (see
15
+ * `vitest.config.mjs`: `environment: "node"`). Rather than add that
16
+ * infrastructure for one regression test, this renders through
17
+ * `react-dom/server`'s `renderToStaticMarkup` — a real React render pass
18
+ * (the same kind that ran the old, buggy read) that needs no DOM. Calling
19
+ * it repeatedly stands in for repeated re-renders: each call re-executes
20
+ * every component's render body, which is exactly the code path the bug
21
+ * lived in.
22
+ */
23
+ import { CopilotKit } from "@copilotkit/react-core";
24
+ import { renderToStaticMarkup } from "react-dom/server";
25
+ import { describe, expect, it } from "vitest";
26
+ import { defaultSuggestionsApiConfig } from "../../../types/autosuggestions-config/suggestions-api-config";
27
+ import { useMakeStandardAutosuggestionFunction } from "../use-make-standard-autosuggestions-function";
28
+
29
+ function Probe() {
30
+ // Same call shape as `CopilotTextarea` (see copilot-textarea.tsx:208-212).
31
+ useMakeStandardAutosuggestionFunction(
32
+ "a test textarea",
33
+ ["global"],
34
+ defaultSuggestionsApiConfig,
35
+ );
36
+ return null;
37
+ }
38
+
39
+ describe("useMakeStandardAutosuggestionFunction — async headers builder (#1937)", () => {
40
+ it("never calls an async headers builder during render, across repeated renders", () => {
41
+ let builderCalls = 0;
42
+
43
+ function App() {
44
+ return (
45
+ <CopilotKit
46
+ runtimeUrl="http://rt.test/api/copilotkit"
47
+ headers={async () => {
48
+ builderCalls++;
49
+ return { Authorization: "Bearer tok-1" };
50
+ }}
51
+ >
52
+ <Probe />
53
+ </CopilotKit>
54
+ );
55
+ }
56
+
57
+ // Discriminating assertion FIRST: mounting is itself a render, and the
58
+ // old code called the builder right there, in `useMakeStandard...`'s
59
+ // hook body, before any effect ever ran.
60
+ renderToStaticMarkup(<App />);
61
+ expect(builderCalls).toBe(0);
62
+
63
+ // Repeated renders (each call is a fresh, independent render pass
64
+ // through the same tree) must never invoke the builder either — the
65
+ // bug scaled with render COUNT, not just with mounting once.
66
+ for (let i = 0; i < 10; i++) {
67
+ renderToStaticMarkup(<App />);
68
+ }
69
+ expect(builderCalls).toBe(0);
70
+ });
71
+ });
@@ -1,12 +1,11 @@
1
- import { COPILOT_CLOUD_PUBLIC_API_KEY_HEADER } from "@copilotkit/shared";
2
1
  import { useCopilotContext } from "@copilotkit/react-core";
3
2
  import { useCallback } from "react";
4
- import { AutosuggestionsBareFunction } from "../../types";
3
+ import type { AutosuggestionsBareFunction } from "../../types";
5
4
  import { retry } from "../../lib/retry";
6
- import { InsertionEditorState } from "../../types/base/autosuggestions-bare-function";
7
- import { SuggestionsApiConfig } from "../../types/autosuggestions-config/suggestions-api-config";
5
+ import type { InsertionEditorState } from "../../types/base/autosuggestions-bare-function";
6
+ import type { SuggestionsApiConfig } from "../../types/autosuggestions-config/suggestions-api-config";
7
+ import type { Message } from "@copilotkit/runtime-client-gql";
8
8
  import {
9
- Message,
10
9
  Role,
11
10
  TextMessage,
12
11
  convertGqlOutputToMessages,
@@ -35,18 +34,7 @@ export function useMakeStandardAutosuggestionFunction(
35
34
  ): AutosuggestionsBareFunction {
36
35
  const runtimeClient = { generateCopilotResponse: (...args: any[]) => {} };
37
36
  const { getContextString, copilotApiConfig } = useCopilotContext();
38
- const {
39
- chatApiEndpoint: url,
40
- publicApiKey,
41
- credentials,
42
- properties,
43
- } = copilotApiConfig;
44
- const headers = {
45
- ...copilotApiConfig.headers,
46
- ...(publicApiKey
47
- ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey }
48
- : {}),
49
- };
37
+ const { chatApiEndpoint: url, credentials, properties } = copilotApiConfig;
50
38
  const { maxTokens, stop, temperature = 0 } = apiConfig;
51
39
 
52
40
  return useCallback(
package/vitest.config.mjs CHANGED
@@ -4,7 +4,7 @@ export default defineConfig({
4
4
  test: {
5
5
  environment: "node",
6
6
  globals: true,
7
- include: ["src/**/*.{test,spec}.ts"],
7
+ include: ["src/**/*.{test,spec}.{ts,tsx}"],
8
8
  reporters: [["default", { summary: false }]],
9
9
  silent: true,
10
10
  },