Problem with Embed PDF: [mobx] Invariant failed: Since strict-mode is enabled
Hi,
I'm just getting started with Embed PDF...
When I try to load a PDF I get the error:
Uncaught Error: [mobx] Invariant failed: Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an `action` if this change is intended. Tried to modify: AppStore@40.isHidingBranding
at nt (dc-mobx.js:16)
at tt (dc-mobx.js:16)
at Xt (dc-mobx.js:16)
at t.prepareNewValue (dc-mobx.js:16)
at Se (dc-mobx.js:16)
at AppStore.set [as isHidingBranding] (dc-mobx.js:16)
at AppStore.initialize (AdobeDCViewApp.js:2)
at JAOs.window.renderApp (AdobeDCViewApp.js:2)
at MessageExecutor._executeAction (ViewSDK.js:1)
at MessageExecutor._takeAction (ViewSDK.js:1)To be honest I'm not sure what this "really" means but I wasn't expecting to have to figure out what "mobex actions" are to try and get this working... 😞
The application is a simple "lit html" web components based app running entirely client side.
In the page HTML I use an event listener to mark when the sdk is ready:
<script src="https://documentcloud.adobe.com/view-sdk/main.js"></script>
<script type="text/javascript">
var adobeDcSdkReady = false;
var adobeDCView;
document.addEventListener("adobe_dc_view_sdk.ready", function() {
console.log(`addEventListener (adobe dc) - triggered`);
adobeDcSdkReady = true;
});
</script> Then in a window.onload function (which uses ES6 imports, so is probably running in javascript strict mode) I initialise the viewer:
if (adobeDcSdkReady) {
console.log(`window onload (adobe dc) - key is: ${adobeEmbedPdfKey}`);
adobeDCView = new AdobeDC.View({clientId: adobeEmbedPdfKey, divId: "adobe-dc-view"});
} else {
console.log(`window onload (adobe dc) - not ready`);
}In the browser console I see the line "window onload (adobe dc) - key is", so I think the viewer is being created with a valid key after the sdk is initialised.
Finally I try to view a PDF file (which is available as an ArrayBuffer) by doing:
if ((this.pdfFileArrayBuffer) && (this.adobeDCView)) {
this.adobeDCView.previewFile({
content: { promise: this.pdfFileArrayBuffer },
metaData: { fileName: "preview.pdf" }
});
}This is where the exception (at the top of this post) is thrown.
Any suggestions/pointers gratefully received.
Cheers, Andy
