Commit 7f32c5ee authored by Robert Knight's avatar Robert Knight

Add/revise some comments to address PR feedback

Clarify what happens if we try to test whether a VitalSource frame
contains "real content", before it has finished loading.
parent ee8036cd
...@@ -67,6 +67,9 @@ export class VitalSourceContainerIntegration { ...@@ -67,6 +67,9 @@ export class VitalSourceContainerIntegration {
// //
// The format of the decoded HTML can vary, but as a simple heuristic, // The format of the decoded HTML can vary, but as a simple heuristic,
// we look for a text paragraph. // we look for a text paragraph.
//
// If the document has not yet finished loading, then we rely on this function
// being called again once loading completes.
const isBookContent = frame.contentDocument?.querySelector('p'); const isBookContent = frame.contentDocument?.querySelector('p');
if (isBookContent) { if (isBookContent) {
annotator.injectClient(frame); annotator.injectClient(frame);
...@@ -77,6 +80,7 @@ export class VitalSourceContainerIntegration { ...@@ -77,6 +80,7 @@ export class VitalSourceContainerIntegration {
const injectClientIntoContentFrame = () => { const injectClientIntoContentFrame = () => {
const frame = shadowRoot.querySelector('iframe'); const frame = shadowRoot.querySelector('iframe');
if (!frame || contentFrames.has(frame)) { if (!frame || contentFrames.has(frame)) {
// Either there is no content frame or we are already watching it.
return; return;
} }
contentFrames.add(frame); contentFrames.add(frame);
...@@ -90,9 +94,6 @@ export class VitalSourceContainerIntegration { ...@@ -90,9 +94,6 @@ export class VitalSourceContainerIntegration {
injectClientIntoContentFrame(); injectClientIntoContentFrame();
// Re-inject client into content frame after a chapter navigation. // Re-inject client into content frame after a chapter navigation.
//
// We currently don't do any debouncing here and rely on `injectClient` to
// be idempotent and cheap.
this._frameObserver = new MutationObserver(injectClientIntoContentFrame); this._frameObserver = new MutationObserver(injectClientIntoContentFrame);
this._frameObserver.observe(shadowRoot, { childList: true, subtree: true }); this._frameObserver.observe(shadowRoot, { childList: true, subtree: true });
} }
......
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