|
13 | 13 | // code block's Copy button, a client component in a slot in that block. |
14 | 14 | import { createMemo, For, Loading, onCleanup } from "solid-js"; |
15 | 15 | import { dynamicComponent, getRequestEvent, redirect } from "@solidjs/web"; |
16 | | -import { GET, live } from "@solidjs/web/server-functions"; |
| 16 | +import { live } from "@solidjs/web/server-functions"; |
17 | 17 | import type { Slot } from "@solidjs/web/frames"; |
18 | 18 | import { formAction, liveQuery, type RouteSectionProps } from "@solidjs/router"; |
19 | 19 | import Composer from "~/components/composer"; |
@@ -69,49 +69,47 @@ const deleteThread = formAction(async (id: string) => { |
69 | 69 | // gives it a key and one connection per thread, and tells the router that |
70 | 70 | // this address is kept fresh by its own stream. |
71 | 71 | const getThread = liveQuery( |
72 | | - live( |
73 | | - GET(async (id: string) => { |
74 | | - "use server"; |
75 | | - return (props: { composer: ComposerSlot; copyCode: CopySlot }) => { |
76 | | - // This render lives as long as its response. When the tab goes away |
77 | | - // the watcher below is told at once. |
78 | | - const gone = new AbortController(); |
79 | | - onCleanup(() => gone.abort()); |
80 | | - getRequestEvent()?.request.signal.addEventListener("abort", () => gone.abort(), { |
81 | | - once: true |
82 | | - }); |
| 72 | + live(async (id: string) => { |
| 73 | + "use server"; |
| 74 | + return (props: { composer: ComposerSlot; copyCode: CopySlot }) => { |
| 75 | + // This render lives as long as its response. When the tab goes away |
| 76 | + // the watcher below is told at once. |
| 77 | + const gone = new AbortController(); |
| 78 | + onCleanup(() => gone.abort()); |
| 79 | + getRequestEvent()?.request.signal.addEventListener("abort", () => gone.abort(), { |
| 80 | + once: true |
| 81 | + }); |
83 | 82 |
|
84 | | - // The thread as it is stored, again after every write to it. |
85 | | - const view = createMemo(() => db.watchThread(id, gone.signal)); |
| 83 | + // The thread as it is stored, again after every write to it. |
| 84 | + const view = createMemo(() => db.watchThread(id, gone.signal)); |
86 | 85 |
|
87 | | - return ( |
88 | | - <article class="thread"> |
89 | | - <header class="thread-head"> |
90 | | - {headMarkup(view().thread)} |
91 | | - <p class="muted">Answered by {model.modelName()}</p> |
92 | | - </header> |
93 | | - <ol class="messages"> |
94 | | - {/* A row the server has already rendered is kept while its |
| 86 | + return ( |
| 87 | + <article class="thread"> |
| 88 | + <header class="thread-head"> |
| 89 | + {headMarkup(view().thread)} |
| 90 | + <p class="muted">Answered by {model.modelName()}</p> |
| 91 | + </header> |
| 92 | + <ol class="messages"> |
| 93 | + {/* A row the server has already rendered is kept while its |
95 | 94 | message is unchanged, so a streaming reply doesn't render |
96 | 95 | the whole history again on every write (#4056). */} |
97 | | - <For each={view().messages.filter(m => m.status !== "generating")}> |
98 | | - {message => messageMarkup(message, props.copyCode)} |
99 | | - </For> |
100 | | - {messagesMarkup(view().messages, true, props.copyCode)} |
101 | | - </ol> |
102 | | - {/* Keyed by thread: going to another conversation is a new |
| 96 | + <For each={view().messages.filter(m => m.status !== "generating")}> |
| 97 | + {message => messageMarkup(message, props.copyCode)} |
| 98 | + </For> |
| 99 | + {messagesMarkup(view().messages, true, props.copyCode)} |
| 100 | + </ol> |
| 101 | + {/* Keyed by thread: going to another conversation is a new |
103 | 102 | composer, so a half-typed message stays with its thread. */} |
104 | | - <props.composer |
105 | | - $key={id} |
106 | | - threadId={id} |
107 | | - seen={view().messages.map(m => m.id)} |
108 | | - busy={view().messages.some(m => m.status === "generating")} |
109 | | - /> |
110 | | - </article> |
111 | | - ); |
112 | | - }; |
113 | | - }) |
114 | | - ), |
| 103 | + <props.composer |
| 104 | + $key={id} |
| 105 | + threadId={id} |
| 106 | + seen={view().messages.map(m => m.id)} |
| 107 | + busy={view().messages.some(m => m.status === "generating")} |
| 108 | + /> |
| 109 | + </article> |
| 110 | + ); |
| 111 | + }; |
| 112 | + }), |
115 | 113 | "thread" |
116 | 114 | ); |
117 | 115 |
|
|
0 commit comments