@eshal-bot/chat-widget 0.2.1 → 0.2.3

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.
@@ -91200,7 +91200,46 @@
91200
91200
  };
91201
91201
  }
91202
91202
 
91203
- const WidgetCitationContext = /*#__PURE__*/React.createContext(null);
91203
+ /**
91204
+ * WidgetCitationContext - the message's `sources` array + download handler,
91205
+ * supplied by `<MessageBubble>` and consumed by every `<CitationPill>` that
91206
+ * `rehypeCitations` renders inside the ReactMarkdown output.
91207
+ *
91208
+ * EV-2904 - WHY THIS LIVES IN ITS OWN MODULE, BEHIND A GLOBAL SINGLETON
91209
+ * ---------------------------------------------------------------------
91210
+ * The vanilla/IIFE build (`chat-widget.min.js` - the `<script src=...>`
91211
+ * snippet customers actually install) ships the markdown pipeline as a
91212
+ * SEPARATE IIFE bundle, `chat-widget-markdown-chunk.min.js`, injected at
91213
+ * runtime by vanilla/lazyChunkLoader.js. Per rollup.config.js, `react` is
91214
+ * the ONLY module the two bundles share (via the `__eshalChatWidgetReact`
91215
+ * global) - every other module, including this one, is bundled a SECOND
91216
+ * time into the chunk.
91217
+ *
91218
+ * The provider (`MessageBubble.jsx`) lives in the main bundle; the consumer
91219
+ * (`CitationPill.jsx`) is pulled in by `MarkdownRenderer.jsx` and therefore
91220
+ * lives in the chunk. With a plain `createContext(null)` in each bundle,
91221
+ * those are two DIFFERENT context objects: the pill's `useContext` finds no
91222
+ * matching Provider above it, falls back to the default `null`, and
91223
+ * `CitationPill` returns `null` (its "rendered outside a chat" guard). The
91224
+ * result is that citations silently vanish on the installed widget - no
91225
+ * error, no raw `[N]` leak - while the Testing Lab and the ESM/UMD builds
91226
+ * (single module graph) render them fine.
91227
+ *
91228
+ * Stashing the context object on a `window` key makes it a true
91229
+ * cross-bundle singleton: whichever bundle evaluates first creates it, the
91230
+ * other reuses it, so provider and consumer always agree. Safe for the
91231
+ * single-graph builds too - the second import just re-reads the same
91232
+ * object, which is exactly what a plain module-level `createContext` did.
91233
+ *
91234
+ * `createContext` must come from the one shared React instance for hooks to
91235
+ * work at all; rollup.config.js already guarantees that via the
91236
+ * `__eshalChatWidgetReact` global, so the object created here is valid in
91237
+ * both bundles.
91238
+ */
91239
+ const GLOBAL_KEY = "__eshalChatWidgetCitationContext";
91240
+ const globalScope = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : undefined;
91241
+ const WidgetCitationContext = globalScope ? globalScope[GLOBAL_KEY] || (globalScope[GLOBAL_KEY] = /*#__PURE__*/React.createContext(null)) : /*#__PURE__*/React.createContext(null);
91242
+
91204
91243
  function decodeName(name) {
91205
91244
  if (!name) return "";
91206
91245
  try {