@extend-ai/react-docx 0.8.3 → 0.8.4

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/dist/index.js CHANGED
@@ -26999,6 +26999,7 @@ var DocxDetachedThumbnailSurfaceRenderer = class {
26999
26999
  root;
27000
27000
  activePageIndex;
27001
27001
  activeRenderKey;
27002
+ rootGeneration = 0;
27002
27003
  async renderPageSurface(params) {
27003
27004
  if (typeof document === "undefined" || typeof window === "undefined") {
27004
27005
  return void 0;
@@ -27024,16 +27025,24 @@ var DocxDetachedThumbnailSurfaceRenderer = class {
27024
27025
  return this.waitForPageSurface(registry, pageIndex);
27025
27026
  }
27026
27027
  clear() {
27027
- if (this.root) {
27028
- this.root.unmount();
27029
- this.root = void 0;
27030
- }
27031
- if (this.host?.parentNode) {
27032
- this.host.parentNode.removeChild(this.host);
27033
- }
27028
+ const root = this.root;
27029
+ const host = this.host;
27030
+ this.rootGeneration += 1;
27031
+ this.root = void 0;
27034
27032
  this.host = void 0;
27035
27033
  this.activePageIndex = void 0;
27036
27034
  this.activeRenderKey = void 0;
27035
+ const dispose = () => {
27036
+ root?.unmount();
27037
+ if (host?.parentNode) {
27038
+ host.parentNode.removeChild(host);
27039
+ }
27040
+ };
27041
+ if (root && typeof window !== "undefined") {
27042
+ window.setTimeout(dispose, 0);
27043
+ } else {
27044
+ dispose();
27045
+ }
27037
27046
  }
27038
27047
  async ensureRoot() {
27039
27048
  if (this.root) {
@@ -27042,6 +27051,7 @@ var DocxDetachedThumbnailSurfaceRenderer = class {
27042
27051
  if (typeof document === "undefined") {
27043
27052
  return;
27044
27053
  }
27054
+ const generation = this.rootGeneration;
27045
27055
  const host = document.createElement("div");
27046
27056
  host.setAttribute("data-docx-thumbnail-detached-renderer", "true");
27047
27057
  Object.assign(host.style, {
@@ -27058,6 +27068,12 @@ var DocxDetachedThumbnailSurfaceRenderer = class {
27058
27068
  document.body.appendChild(host);
27059
27069
  this.host = host;
27060
27070
  const { createRoot } = await import("react-dom/client");
27071
+ if (generation !== this.rootGeneration) {
27072
+ if (host.parentNode) {
27073
+ host.parentNode.removeChild(host);
27074
+ }
27075
+ return;
27076
+ }
27061
27077
  this.root = createRoot(host);
27062
27078
  }
27063
27079
  async waitForPageSurface(registry, pageIndex) {