Commit fa99d0bd authored by Robert Knight's avatar Robert Knight

Initialize `target` property of new page notes to a single-item array

Annotations received from the API always have a non-empty `target` array, as do
annotations and replies created locally that have not yet been saved. Unsaved
Page Notes were an exception. This led to an error [1] when hovering a new
unsaved page note in a VitalSource book, due to code not handling an empty
`target` array.  Resolve this by initializing the `target` field of new page
notes in the same way as replies and annotations (minus the `selector` property
that annotations have).

[1] https://hypothesis.sentry.io/issues/3745569320/
parent 930ff477
...@@ -166,7 +166,11 @@ export class AnnotationsService { ...@@ -166,7 +166,11 @@ export class AnnotationsService {
return; return;
} }
const pageNoteAnnotation = { const pageNoteAnnotation = {
target: [], target: [
{
source: topLevelFrame.uri,
},
],
uri: topLevelFrame.uri, uri: topLevelFrame.uri,
}; };
this.create(pageNoteAnnotation); this.create(pageNoteAnnotation);
......
...@@ -279,7 +279,11 @@ describe('AnnotationsService', () => { ...@@ -279,7 +279,11 @@ describe('AnnotationsService', () => {
const annotation = getLastAddedAnnotation(); const annotation = getLastAddedAnnotation();
assert.equal(annotation.uri, 'http://www.example.com'); assert.equal(annotation.uri, 'http://www.example.com');
assert.deepEqual(annotation.target, []); assert.deepEqual(annotation.target, [
{
source: 'http://www.example.com',
},
]);
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment