@kendew-agency/react-feedback-layer 0.4.0-rc.0 → 0.4.0-rc.2

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/README.md CHANGED
@@ -8,6 +8,7 @@ Have a look at the [changelog](#changelog) and the [migration guide](#migrating-
8
8
 
9
9
  - 🎯 **Contextual Feedback** - Click or drag to create comments anywhere on your UI
10
10
  - 🗂️ **Feedback Sessions** - Group comments in a session that moves from draft to confirmed, resolving and resolved
11
+ - 🧭 **Multi-location Sessions** - One session can span several pages. Each page shows only its own comments
11
12
  - 💬 **Comment Lifecycle** - Draft → Published → Resolved, with reopen support
12
13
  - 👥 **User Attribution** - Track who created each comment with timestamps
13
14
  - 🎨 **Fully Customizable** - Headless UI with complete styling control
@@ -49,7 +50,7 @@ import {
49
50
  ToggleOverlayButton,
50
51
  } from '@kendew-agency/react-feedback-layer';
51
52
 
52
- function App({ isReviewer }: { isReviewer: boolean }) {
53
+ function App({ isReviewer, pathname }: { isReviewer: boolean; pathname: string }) {
53
54
  return (
54
55
  <FeedbackSessionProvider
55
56
  canResolveSession={isReviewer}
@@ -64,6 +65,7 @@ function App({ isReviewer }: { isReviewer: boolean }) {
64
65
  onError={(error) => console.error(error.code, error.message)}
65
66
  >
66
67
  <CommentContextProvider
68
+ locationId={pathname} // the page this provider renders, e.g. "/page-a"
67
69
  currentUser={{ name: 'John Doe', id: 'user-123' }}
68
70
  onAdd={(comment) => api.addComment(comment)}
69
71
  onEdit={(comment) => api.editComment(comment)}
@@ -72,7 +74,7 @@ function App({ isReviewer }: { isReviewer: boolean }) {
72
74
  onReopen={(comment) => api.reopenComment(comment)}
73
75
  onError={(error) => console.error(error.code, error.message)}
74
76
  >
75
- <CreateSession>Start feedback session</CreateSession>
77
+ <CreateSession user={{ name: 'John Doe', id: 'user-123' }}>Start feedback session</CreateSession>
76
78
  <ConfirmSession>Confirm session</ConfirmSession>
77
79
  <StartResolving>Start resolving</StartResolving>
78
80
  <ResolveSession>Resolve session</ResolveSession>
@@ -92,20 +94,22 @@ function App({ isReviewer }: { isReviewer: boolean }) {
92
94
  }
93
95
  ```
94
96
 
97
+ `locationId` identifies the page (or screen) that a `CommentContextProvider` renders. Every new comment is stored with it, and the overlay shows only the comments placed at that location. Without a `locationId` the provider shows no comments and refuses to create them. See [Sessions across multiple locations](#sessions-across-multiple-locations).
98
+
95
99
  ## Core Concepts
96
100
 
97
101
  ### Feedback Sessions
98
102
 
99
- Every comment belongs to a feedback session. Only the comments of the active session (`comment.sessionId === session.id`) are visible. Without a session no comment is shown and no comment can be added.
103
+ Every comment belongs to a feedback session and is placed at a location. A comment is shown only when its `sessionId` equals the id of the active session and its `locationId` equals the `locationId` prop of the `CommentContextProvider`. The overlay therefore shows the active session's comments at that location. Comments without a `locationId` are hidden. Without a session no comment is shown and no comment can be added.
100
104
 
101
105
  #### Session flow
102
106
 
103
- 1. **Create the session.** Call `createSession()` (or render `<CreateSession />`). The provider calls `onCreateSession`, stores the returned session as a `draft` and emits `onSessionCreated`.
107
+ 1. **Create the session.** Call `createSession({ user })` (or render `<CreateSession user={user} />`). The provider calls `onCreateSession`, stores the returned session as a `draft` and emits `onSessionCreated`.
104
108
  2. **Add draft comments.** While the session is a `draft`, click or drag on the overlay to register a comment, write content and confirm it with `Comment.Confirm`. Confirming a comment calls `onAdd` and turns the comment from `draft` into `published`. Published comments can be edited (`onEdit`) and deleted (`onDelete`) as long as the session is a `draft`.
105
- 3. **Confirm the session.** Call `confirmSession()` (or render `<ConfirmSession />`). It calls `onConfirmSession(sessionId, type)`, sets `confirmedAt` and emits `onSessionConfirmed`. It is refused with a `SessionStateError` when the session is not a draft, when a local draft comment still exists, or when the session has no comments.
109
+ 3. **Confirm the session.** Call `confirmSession()` (or render `<ConfirmSession />`). It calls `onConfirmSession(sessionId, type)`, sets `confirmedAt` and emits `onSessionConfirmed`. It is refused with a `SessionStateError` when the session is not a draft, when a local draft comment still exists (in any `CommentContextProvider`), or when the session has no comments at any location. Comments without a `locationId` are ignored by this check, so they do not count as a comment.
106
110
  4. **Start resolving.** Call `startResolving()` (or render `<StartResolving />`). It calls `onStartResolving(sessionId)` and emits `onSessionResolving`. Requires `canResolveSession` and a `confirmed` session.
107
111
  5. **Resolve comments.** While the session is `resolving`, resolve each published comment with `resolveComment(id)` or `<Comment.Resolve />`, and reopen resolved comments with `reopenComment(id)` or `<Comment.Reopen />`. Requires `canResolveSession`.
108
- 6. **Resolve the session.** Call `resolveSession()` (or render `<ResolveSession />`). It calls `onResolveSession(sessionId)`, sets `resolvedAt` and emits `onSessionResolved`. Requires `canResolveSession`, a `resolving` session and no comment that is still `published`.
112
+ 6. **Resolve the session.** Call `resolveSession()` (or render `<ResolveSession />`). It calls `onResolveSession(sessionId)`, sets `resolvedAt` and emits `onSessionResolved`. Requires `canResolveSession`, a `resolving` session and no comment that is still `published` at any location. Comments without a `locationId` are ignored by this check, so they cannot block it.
109
113
 
110
114
  #### Session status
111
115
 
@@ -114,9 +118,9 @@ Every comment belongs to a feedback session. Only the comments of the active ses
114
118
  | From | To | Triggered by | Requires |
115
119
  |------|----|--------------|----------|
116
120
  | (none) | `draft` | `createSession()` | No other draft session, `onCreateSession` provided |
117
- | `draft` | `confirmed` | `confirmSession()` | No local draft comments, at least one comment |
121
+ | `draft` | `confirmed` | `confirmSession()` | No local draft comments, at least one comment with a `locationId` |
118
122
  | `confirmed` | `resolving` | `startResolving()` | `canResolveSession` |
119
- | `resolving` | `resolved` | `resolveSession()` | `canResolveSession`, no `published` comment left |
123
+ | `resolving` | `resolved` | `resolveSession()` | `canResolveSession`, no `published` comment with a `locationId` left |
120
124
 
121
125
  No other transitions exist. A transition is committed only after its callback resolves. When the callback throws or rejects, the status stays as it was and `onError` receives the error.
122
126
 
@@ -131,6 +135,45 @@ What each status allows:
131
135
 
132
136
  Calls that are not allowed return `{ error }` with a `SessionStateError` and call `onError`. Calls without permission return a `PermissionError`.
133
137
 
138
+ ### Sessions across multiple locations
139
+
140
+ One feedback session can cover several pages. Render one `CommentContextProvider` per page, each with its own `locationId`, inside the same `FeedbackSessionProvider`.
141
+
142
+ - The session holds the comments of all locations. Each provider shows only the comments at its own `locationId`.
143
+ - `confirmSession()` and `resolveSession()` check the comments of all locations, not only the current page. `confirmSession()` also sums the local drafts of all providers.
144
+ - Comments without a `locationId` (for example legacy data) are hidden everywhere and ignored by these checks. They are not deleted or changed.
145
+ - Keep the `FeedbackSessionProvider` mounted while the user navigates, so the session stays the same.
146
+
147
+ ```tsx
148
+ // The same session across /page-a, /page-b and /page-c
149
+ function PageA() {
150
+ return (
151
+ <CommentContextProvider locationId="page-a" currentUser={user} onAdd={saveComment}>
152
+ <CommentOverlay>
153
+ <PageAContent />
154
+ <CommentRenderer {...renderers} />
155
+ </CommentOverlay>
156
+ </CommentContextProvider>
157
+ );
158
+ }
159
+ // PageB and PageC are the same with locationId="page-b" and "page-c"
160
+ function App() {
161
+ return (
162
+ <FeedbackSessionProvider initialSession={savedSession} onConfirmSession={confirmSession}>
163
+ <Router>
164
+ <Route path="/page-a" element={<PageA />} />
165
+ <Route path="/page-b" element={<PageB />} />
166
+ <Route path="/page-c" element={<PageC />} />
167
+ {/* Confirming on /page-c confirms the comments of all three pages */}
168
+ <ConfirmSession>Confirm session</ConfirmSession>
169
+ </Router>
170
+ </FeedbackSessionProvider>
171
+ );
172
+ }
173
+ ```
174
+
175
+ To see the comments at the current location from other sessions as well, use [`commentsBySession`](#usecomments).
176
+
134
177
  ### Comment Lifecycle
135
178
 
136
179
  Comments have three statuses:
@@ -203,12 +246,12 @@ type FeedbackSessionProviderProps = {
203
246
 
204
247
  type CreateSessionInput = {
205
248
  type: SessionType; // "feedback"
206
- user: User | null;
249
+ user: User;
207
250
  projectId?: string | undefined;
208
251
  };
209
252
  ```
210
253
 
211
- `createSession` is refused when `onCreateSession` is not provided, when a draft session already exists, when a creation is in progress, or when `projectId` is not 1 to 128 characters long.
254
+ `createSession` is refused when `user` is missing, when `onCreateSession` is not provided, when a draft session already exists, when a creation is in progress, or when `projectId` is not 1 to 128 characters long.
212
255
 
213
256
  `initialSession` must have a valid `status`. Otherwise the provider starts without a session and reports a `SessionStateError` once on mount. Its `comments` are optional and default to an empty array.
214
257
 
@@ -228,18 +271,6 @@ type CreateSessionInput = {
228
271
  </FeedbackSessionProvider>
229
272
  ```
230
273
 
231
- #### `UserProvider`
232
-
233
- Optional. Shares the current user with the session provider and the comment provider. When a `UserProvider` is present, its `user` takes precedence over the `currentUser` prop of `CommentContextProvider`.
234
-
235
- ```tsx
236
- <UserProvider user={{ id: 'user-123', name: 'John Doe' }}>
237
- <FeedbackSessionProvider>{/* ... */}</FeedbackSessionProvider>
238
- </UserProvider>
239
- ```
240
-
241
- Use `useCurrentUser()` to read the user (`User | null`). It throws outside a `UserProvider`.
242
-
243
274
  #### `CommentContextProvider`
244
275
 
245
276
  The provider that manages comment state and comment actions. It throws when it is not rendered inside a `FeedbackSessionProvider`. Standalone use is no longer possible.
@@ -248,11 +279,19 @@ The provider that manages comment state and comment actions. It throws when it i
248
279
 
249
280
  ```tsx
250
281
  type CommentOverlayProps = {
251
- // Comments to start with. Defaults to the comments of the session.
252
- // Each comment needs a sessionId equal to the initialSession id.
282
+ // Comments to start with, from all locations. Defaults to the comments of the session.
283
+ // Each comment needs a sessionId and a locationId. Comments of other sessions
284
+ // are kept, but they only appear in commentsBySession.
253
285
  initialComments?: ConfirmedComment[];
254
-
255
- // Current logged-in user (default: null). Ignored when a UserProvider exists.
286
+ // The location this provider renders, for example a page name or pathname.
287
+ // New comments are stored with this id and the overlay shows only the
288
+ // comments at this location. Comments of all locations are loaded, so
289
+ // session-level checks see them.
290
+ // When missing or an empty string, no comments are shown and
291
+ // registerComment reports an AddError through onError without creating a draft.
292
+ locationId?: string;
293
+
294
+ // Current logged-in user (default: null).
256
295
  currentUser?: User | null;
257
296
 
258
297
  children: ReactNode;
@@ -300,12 +339,13 @@ type CommentOverlayProps = {
300
339
  | `onResolve` | A published comment is resolved | The comment with status `resolved` and `resolvedAt` |
301
340
  | `onReopen` | A resolved comment is reopened | The comment with status `published` and no `resolvedAt` |
302
341
 
303
- Every callback is optional. When a callback throws or rejects, the change is not applied and `onError` receives an `AddError`, `EditError`, `DeleteError`, `ResolveError` or `ReopenError`. Deleting a local draft does not call `onDelete`.
342
+ Every comment passed to a callback keeps its `locationId`. Every callback is optional. When a callback throws or rejects, the change is not applied and `onError` receives an `AddError`, `EditError`, `DeleteError`, `ResolveError` or `ReopenError`. Deleting a local draft does not call `onDelete`.
304
343
 
305
344
  **Example:**
306
345
 
307
346
  ```tsx
308
347
  <CommentContextProvider
348
+ locationId="page-a"
309
349
  currentUser={{ name: 'Jane Smith', id: '456', avatar: '/avatar.jpg' }}
310
350
  initialComments={existingComments}
311
351
  projectId="proj_123456789"
@@ -572,10 +612,10 @@ Toggles the comment overlay on/off. Sets `data-active` when the overlay is not i
572
612
 
573
613
  ##### `CreateSession`, `ConfirmSession`, `StartResolving`, `ResolveSession`
574
614
 
575
- Call `createSession()`, `confirmSession()`, `startResolving()` and `resolveSession()` of `useFeedbackSession()`. They must be rendered inside a `FeedbackSessionProvider`.
615
+ Call `createSession({ user })`, `confirmSession()`, `startResolving()` and `resolveSession()` of `useFeedbackSession()`. They must be rendered inside a `FeedbackSessionProvider`.
576
616
 
577
617
  ```tsx
578
- <CreateSession>New session</CreateSession>
618
+ <CreateSession user={currentUser}>New session</CreateSession>
579
619
  <ConfirmSession>Confirm</ConfirmSession>
580
620
  <StartResolving>Start resolving</StartResolving>
581
621
  <ResolveSession>Finish</ResolveSession>
@@ -605,9 +645,9 @@ type FeedbackSessionContextType = {
605
645
  // Mirrors the canResolveSession prop
606
646
  canResolve: boolean;
607
647
 
608
- createSession: (options?: {
648
+ createSession: (options: {
649
+ user: User; // required
609
650
  type?: SessionType;
610
- user?: User | null;
611
651
  projectId?: string;
612
652
  }) => Promise<{ error: KnownError | null }>;
613
653
  confirmSession: () => Promise<{ error: KnownError | null }>;
@@ -619,7 +659,7 @@ type FeedbackSessionContextType = {
619
659
  };
620
660
  ```
621
661
 
622
- `createSession` defaults `type` to `"feedback"`, `user` to the `UserProvider` user, and `projectId` to the provider `projectId`. A failed or refused action returns `{ error }` and also calls `onError`. A second call of the same transition while it is pending resolves with `{ error: null }` and does nothing.
662
+ `createSession` requires `user`. It defaults `type` to `"feedback"` and `projectId` to the provider `projectId`. Without a `user` it is refused with a `SessionCreateError` ("user is required"), returned as `{ error }` and passed to `onError`, and `onCreateSession` is not called. A failed or refused action returns `{ error }` and also calls `onError`. A second call of the same transition while it is pending resolves with `{ error: null }` and does nothing.
623
663
 
624
664
  ```tsx
625
665
  function SessionToolbar() {
@@ -684,11 +724,14 @@ Access the comment context and actions. Throws outside a `CommentContextProvider
684
724
 
685
725
  ```tsx
686
726
  interface CommentContext {
687
- // Comments of the active session, after the draftVisibility filter
727
+ // Comments of the active session at the current location, after the
728
+ // draftVisibility filter. Empty without a locationId or a session.
688
729
  draftComments: CommentType[];
689
730
  comments: CommentType[]; // Published comments
690
731
  resolvedComments: CommentType[];
691
732
  allComments: CommentType[];
733
+ // Comments at the current location, grouped by session id
734
+ commentsBySession: Record<string, CommentType[]>;
692
735
 
693
736
  // State
694
737
  overlayState: CommentOverlayState;
@@ -718,6 +761,24 @@ interface CommentContext {
718
761
  }
719
762
  ```
720
763
 
764
+ `commentsBySession` groups the comments at the current location by session id. It includes sessions other than the active one, so you can show earlier feedback next to the active session. Keep in mind:
765
+
766
+ - Only sessions that have at least one comment at the current location have a key. Other sessions are omitted.
767
+ - `config.draftVisibility` applies only to the entry of the active session. Other sessions are not filtered.
768
+ - The order of the comments follows the loaded comments. Comments without a `locationId` are excluded, and the record is empty when the provider has no `locationId`.
769
+ - `draftComments`, `comments`, `resolvedComments` and `allComments` are not affected. They still hold only the active session.
770
+ - Comments of other sessions get into the provider through `initialComments`. The session itself only carries its own comments.
771
+
772
+ ```tsx
773
+ function EarlierFeedback({ sessionId }: { sessionId: string }) {
774
+ const { commentsBySession } = useComments();
775
+ const earlier = commentsBySession[sessionId] ?? [];
776
+ return <span>{earlier.length} comments from session {sessionId} on this page</span>;
777
+ }
778
+ ```
779
+
780
+ `registerComment` stores the current `locationId` on the new draft. Without a `locationId` it reports an `AddError` through `onError` and creates no draft.
781
+
721
782
  `updateComment` adds a draft comment (`onAdd`) or edits a published one (`onEdit`). It needs a `draft` session and rejects empty content for new comments. `resolveComment` and `reopenComment` need a `resolving` session and `canResolveSession`, and they do nothing (`{ error: null }`) when the comment is already in the target status.
722
783
 
723
784
  **Example:**
@@ -825,7 +886,7 @@ import type {
825
886
 
826
887
  ### Draft visibility
827
888
 
828
- `config.draftVisibility` controls whether comments that other users already persisted are shown while the session is a draft.
889
+ `config.draftVisibility` controls whether comments that other users already persisted are shown while the session is a draft. It applies to the comments at the current location.
829
890
 
830
891
  | Value | Effect while the session is a `draft` |
831
892
  |-------|----------------------------------------|
@@ -835,7 +896,7 @@ import type {
835
896
  - The default is `"visible"`. Any other value falls back to `"visible"`.
836
897
  - It only applies while the session status is `draft`. Once the session is `confirmed`, `resolving` or `resolved`, all comments of the session are shown.
837
898
  - Your own local drafts are always shown. Comments without a `user.id` are also shown.
838
- - Hidden comments are removed from `draftComments`, `comments`, `resolvedComments` and `allComments`.
899
+ - Hidden comments are removed from `draftComments`, `comments`, `resolvedComments` and `allComments`, and from the active session's entry of `commentsBySession`.
839
900
 
840
901
  ```tsx
841
902
  <CommentContextProvider config={{ draftVisibility: 'hidden' }} /* ... */>
@@ -880,12 +941,17 @@ type CommentType = {
880
941
  status: "draft" | "published" | "resolved";
881
942
  indicator?: Indicator | null;
882
943
  sessionId: string;
944
+ // The location the comment was placed at, equal to the locationId prop of
945
+ // the provider. Comments without it are hidden.
946
+ locationId: string;
883
947
  projectId?: string;
884
948
  };
885
949
 
886
- // A persisted comment, as passed to onAdd, onEdit, onResolve and onReopen
950
+ // A persisted comment, as passed to onAdd, onEdit, onResolve and onReopen.
951
+ // It has the required locationId of CommentType.
887
952
  type ConfirmedComment = Omit<CommentType, "status"> & {
888
953
  status: "published" | "resolved";
954
+ locationId: string;
889
955
  };
890
956
  ```
891
957
 
@@ -1034,7 +1100,7 @@ function ResolvedComment({ comment }) {
1034
1100
  );
1035
1101
  }
1036
1102
 
1037
- function App() {
1103
+ function App({ pathname }: { pathname: string }) {
1038
1104
  return (
1039
1105
  <FeedbackSessionProvider
1040
1106
  onCreateSession={async ({ type, user, projectId }) => {
@@ -1051,6 +1117,7 @@ function App() {
1051
1117
  onError={(error) => console.error(error.code, error.message)}
1052
1118
  >
1053
1119
  <CommentContextProvider
1120
+ locationId={pathname}
1054
1121
  currentUser={{ name: 'John Doe', id: '123' }}
1055
1122
  onAdd={async (comment) => {
1056
1123
  const response = await fetch('/api/comments', {
@@ -1062,7 +1129,7 @@ function App() {
1062
1129
  onError={(error) => console.error(error.code, error.message)}
1063
1130
  >
1064
1131
  <ToggleOverlayButton>Toggle Feedback Mode</ToggleOverlayButton>
1065
- <CreateSession>Start session</CreateSession>
1132
+ <CreateSession user={currentUser}>Start session</CreateSession>
1066
1133
  <ConfirmSession>Send feedback</ConfirmSession>
1067
1134
 
1068
1135
  <CommentOverlay>
@@ -1081,11 +1148,12 @@ function App() {
1081
1148
 
1082
1149
  ### Resuming a session
1083
1150
 
1084
- Pass the saved session as `initialSession`. Each of its comments, and each entry of `initialComments`, needs a `sessionId` equal to the `initialSession` id. Comments with another `sessionId` are not shown.
1151
+ Pass the saved session as `initialSession`. Each of its comments, and each entry of `initialComments`, needs a `sessionId` and a `locationId`. Comments with a `sessionId` other than the `initialSession` id are kept in `initialComments`, but they are not part of the session. They only appear in `commentsBySession`. Comments without a `locationId` are hidden.
1085
1152
 
1086
1153
  ```tsx
1087
1154
  <FeedbackSessionProvider initialSession={savedSession} canResolveSession>
1088
1155
  <CommentContextProvider
1156
+ locationId={pathname}
1089
1157
  initialComments={savedSession.comments}
1090
1158
  initialOverlayState="idle"
1091
1159
  onError={handleError}
@@ -1095,12 +1163,12 @@ Pass the saved session as `initialSession`. Each of its comments, and each entry
1095
1163
  </FeedbackSessionProvider>
1096
1164
  ```
1097
1165
 
1098
- `initialComments` is optional. Without it, the provider starts with `initialSession.comments`.
1166
+ `initialComments` is optional. Without it, the provider starts with `initialSession.comments`, from all locations. To show earlier sessions at the current location, add their comments to `initialComments` and read them from `commentsBySession`.
1099
1167
 
1100
1168
  ### With Real-time Subscription
1101
1169
 
1102
1170
  ```tsx
1103
- function App() {
1171
+ function App({ pathname }: { pathname: string }) {
1104
1172
  const [subscription, setSubscription] = useState(null);
1105
1173
 
1106
1174
  useEffect(() => {
@@ -1114,6 +1182,7 @@ function App() {
1114
1182
  return (
1115
1183
  <FeedbackSessionProvider onCreateSession={createSession}>
1116
1184
  <CommentContextProvider
1185
+ locationId={pathname}
1117
1186
  currentUser={currentUser}
1118
1187
  subscription={subscription}
1119
1188
  onAdd={saveComment}
@@ -1272,6 +1341,7 @@ Set `projectId` on `FeedbackSessionProvider` to send it to `onCreateSession`, an
1272
1341
  >
1273
1342
  <CommentContextProvider
1274
1343
  projectId="proj_123456789"
1344
+ locationId={pathname}
1275
1345
  onAdd={(comment) => api.addComment(comment)} // comment.projectId is set
1276
1346
  onError={handleError}
1277
1347
  >
@@ -1307,7 +1377,7 @@ function CustomTool() {
1307
1377
  }
1308
1378
  ```
1309
1379
 
1310
- `registerComment` needs a `draft` session. Otherwise `onError` receives a `SessionStateError`.
1380
+ `registerComment` needs a `draft` session. Otherwise `onError` receives a `SessionStateError`. It also needs a `locationId` on the provider. Without one, `onError` receives an `AddError` and no draft is created.
1311
1381
 
1312
1382
  ### Error Handling
1313
1383
 
@@ -1342,7 +1412,7 @@ function ConfirmButton() {
1342
1412
  | `SESSION_RESOLVE_ERROR` | `SessionResolveError` | `onResolveSession` failed |
1343
1413
  | `SESSION_STATE_ERROR` | `SessionStateError` | The action is not allowed in the current session state |
1344
1414
  | `PERMISSION_ERROR` | `PermissionError` | `canResolveSession` is `false` |
1345
- | `ADD_ERROR` | `AddError` | `onAdd` failed or the content is empty |
1415
+ | `ADD_ERROR` | `AddError` | `onAdd` failed, the content is empty or the provider has no `locationId` |
1346
1416
  | `EDIT_ERROR` | `EditError` | `onEdit` failed |
1347
1417
  | `DELETE_ERROR` | `DeleteError` | `onDelete` failed |
1348
1418
  | `RESOLVE_ERROR` | `ResolveError` | `onResolve` failed |
@@ -1424,8 +1494,9 @@ Other breaking changes:
1424
1494
  - **`resolvingComments` is removed** from `useComments()`.
1425
1495
  - **The `hideResolving` filter is removed** from `CommentVisibility` and `config.commentVisibility`. Only `hideResolved` remains.
1426
1496
  - **The `ResolvingComment` prop is removed** from `CommentRenderer`. Pass `Comment`, `DraftComment` and `ResolvedComment`.
1427
- - **`initialComments` need a `sessionId`** equal to the `initialSession` id. Comments of another session are not shown, and without an active session no comments are shown.
1428
- - **`CommentType` has a required `sessionId`** field.
1497
+ - **`initialComments` need a `sessionId` and a `locationId`.** Comments with the `initialSession` id are part of the session. Comments of another session are kept, but they only appear in `commentsBySession`. Without an active session the overlay shows no comments.
1498
+ - **`CommentType` and `ConfirmedComment` have a required `sessionId` and a required `locationId`** field. Comments without a `locationId` are hidden and ignored by `confirmSession` and `resolveSession`. Add a `locationId` to existing stored comments.
1499
+ - **`CommentContextProvider` needs a `locationId`** to show comments or create them. Without it no comments are shown and `registerComment` reports an `AddError`.
1429
1500
  - **`onError` is optional** on both providers.
1430
1501
 
1431
1502
  Before:
@@ -1450,6 +1521,7 @@ After:
1450
1521
  onError={handleError}
1451
1522
  >
1452
1523
  <CommentContextProvider
1524
+ locationId={pathname}
1453
1525
  currentUser={user}
1454
1526
  onAdd={(comment) => api.addComment(comment)}
1455
1527
  onResolve={(comment) => api.resolveComment(comment)}
@@ -1538,6 +1610,7 @@ const comment: CommentType = {
1538
1610
  createdAt: new Date(),
1539
1611
  status: 'published',
1540
1612
  sessionId: 'session-1',
1613
+ locationId: 'page-a',
1541
1614
  };
1542
1615
  ```
1543
1616
 
@@ -1590,10 +1663,14 @@ A list if breaking changes that could impact the way you configured the package
1590
1663
  ### Unreleased
1591
1664
 
1592
1665
  - Added feedback sessions. See [Feedback Sessions](#feedback-sessions) and the [migration guide](#migrating-from-03x). `FeedbackSessionProvider` is now required around `CommentContextProvider`.
1593
- - Added `FeedbackSessionProvider`, `UserProvider`, `useFeedbackSession()`, `useCurrentUser()`, `CreateSession`, `ConfirmSession`, `StartResolving`, `ResolveSession` and `Comment.Reopen`.
1666
+ - Added `FeedbackSessionProvider`, `useFeedbackSession()`, `CreateSession` (takes a required `user` prop), `ConfirmSession`, `StartResolving`, `ResolveSession` and `Comment.Reopen`.
1667
+ - `createSession` takes the user explicitly through `options.user`. There is no user provider: pass `currentUser` to `CommentContextProvider` and `user` to `createSession` or `<CreateSession user>`.
1594
1668
  - Added the `onAdd`, `onEdit`, `onDelete` and `onReopen` callbacks, a single-comment `onResolve`, `resolveComment`, `reopenComment`, `canResolve` and the `config.draftVisibility` option.
1595
1669
  - Added the session events `onSessionCreated`, `onSessionConfirmed`, `onSessionResolving` and `onSessionResolved`, and the comment events `onCommentAdded`, `onCommentEdited`, `onCommentResolved` and `onCommentReopened`.
1596
- - Breaking: removed `confirmComments`, `resolveComments`, `onConfirm`, array `onResolve`, `ConfirmComments`, `ResolveComments`, `onCommentsConfirmed` and `onCommentsResolved`. Removed the `resolving` comment status, `resolvingComments`, the `hideResolving` filter and the `ResolvingComment` renderer prop. Standalone use without a session provider is no longer possible. `initialComments` need a `sessionId` equal to the `initialSession` id.
1670
+ - Breaking: removed `confirmComments`, `resolveComments`, `onConfirm`, array `onResolve`, `ConfirmComments`, `ResolveComments`, `onCommentsConfirmed` and `onCommentsResolved`. Removed the `resolving` comment status, `resolvingComments`, the `hideResolving` filter and the `ResolvingComment` renderer prop. Standalone use without a session provider is no longer possible. `initialComments` need a `sessionId` and a `locationId`.
1671
+ - Added multi-location sessions. See [Sessions across multiple locations](#sessions-across-multiple-locations). Added the `locationId` prop on `CommentContextProvider` and `commentsBySession` on `useComments()`. `confirmSession` and `resolveSession` check the comments of all locations.
1672
+ - Breaking: `locationId` is a required string on `CommentType` and `ConfirmedComment`. A comment is shown only when its `locationId` equals the provider's `locationId` and its `sessionId` equals the active session id. Existing stored comments need a `locationId`, or they are hidden and ignored by `confirmSession` and `resolveSession`. A provider without a `locationId` shows no comments, and `registerComment` reports an `AddError`.
1673
+ - Fixed `Comment.Content` showing a stale or typed draft. It now always renders the saved `comment.content`, so a draft comment shows no text in `Comment.Content` until it is confirmed. The draft of `Comment.Edit` resets when `comment.content` changes, and `defaultDraft` only seeds it on mount.
1597
1674
 
1598
1675
  ### 0.3.2
1599
1676
  - Added `withPosition` prop to `Comment.Root`. It defaults to `true`, so existing behavior is unchanged. Set it to `false` to skip the absolute positioning styles (`position`, `top`, `left`), for example when rendering comments in a list.