* Apply messages from an async `getItem` once it resolves, unless the message * list has already changed since hydration began.
(
persistedMessages:
| Array<UIMessage>
| null
| undefined
| Promise<Array<UIMessage> | null | undefined>,
)
| 90 | * list has already changed since hydration began. |
| 91 | */ |
| 92 | hydrateAsync( |
| 93 | persistedMessages: |
| 94 | | Array<UIMessage> |
| 95 | | null |
| 96 | | undefined |
| 97 | | Promise<Array<UIMessage> | null | undefined>, |
| 98 | ): void { |
| 99 | if (!(persistedMessages instanceof Promise)) { |
| 100 | return |
| 101 | } |
| 102 | |
| 103 | const hydrationGeneration = this.messagesGeneration |
| 104 | persistedMessages |
| 105 | .then((messages) => { |
| 106 | if ( |
| 107 | Array.isArray(messages) && |
| 108 | this.messagesGeneration === hydrationGeneration |
| 109 | ) { |
| 110 | this.applyMessages(messages) |
| 111 | } |
| 112 | }) |
| 113 | .catch(() => { |
| 114 | // Persistence adapters are best-effort and must not break chat setup. |
| 115 | }) |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Record a message-list change and queue a `setItem` write for it. Skips a |
no outgoing calls
no test coverage detected