@descope/web-component 0.0.0-next-94de8ba2-20260626 → 0.0.0-next-f8bdf285-20260715

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplicateFlowWarningMixin.js","sources":["../../../src/lib/mixins/duplicateFlowWarningMixin.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\nimport { compose, createSingletonMixin } from '@descope/sdk-helpers';\nimport { loggerMixin } from '@descope/sdk-mixins';\n\nconst DESCOPE_WC_TAG = 'descope-wc';\nconst PROJECT_ID_ATTR = 'project-id';\nconst FLOW_ID_ATTR = 'flow-id';\n\n/**\n * All `<descope-wc>` elements in `el`'s document that run the same project-id\n * and flow-id as `el` (including `el` itself), in document order. Empty when\n * `el` is missing either attribute.\n */\nexport const getSameFlowInstances = (el: Element): Element[] => {\n const projectId = el.getAttribute(PROJECT_ID_ATTR);\n const flowId = el.getAttribute(FLOW_ID_ATTR);\n if (!projectId || !flowId) return [];\n return Array.from(el.ownerDocument.querySelectorAll(DESCOPE_WC_TAG)).filter(\n (other) =>\n other.getAttribute(PROJECT_ID_ATTR) === projectId &&\n other.getAttribute(FLOW_ID_ATTR) === flowId,\n );\n};\n\n/**\n * True when `el` is a same-flow duplicate that is NOT the first such element in\n * document order. Reporting only from the non-first element means exactly one\n * element per same-flow group reports `true`, so a single warning is emitted\n * regardless of how many duplicates exist. Note: light-DOM only — duplicates\n * nested inside another component's shadow root are intentionally not detected.\n */\nexport const isDuplicateSameFlowInstance = (el: Element): boolean => {\n const sameFlow = getSameFlowInstances(el);\n return sameFlow.length > 1 && sameFlow[0] !== el;\n};\n\n/**\n * Logs a one-time dev warning when more than one `<descope-wc>` on the page runs\n * the same project-id + flow-id. Rendering the same flow more than once is not\n * supported (it causes the post-login screen to flicker, among other issues).\n * Warning only — no behavior change. Hooks `connectedCallback` (not `init`) and\n * pulls in only `loggerMixin`, to avoid participating in the flow `init()` chain.\n */\nexport const duplicateFlowWarningMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) => {\n const BaseClass = compose(loggerMixin)(superclass);\n\n return class DuplicateFlowWarningMixinClass extends BaseClass {\n // The project|flow key this element has already warned for, so we warn at\n // most once per identity. connectedCallback can fire multiple times for\n // the same element (e.g. formMountMixin re-parents it into a <form>), so a\n // plain per-call warning would fire repeatedly.\n #warnedForKey?: string;\n\n #scheduleDuplicateFlowCheck() {\n // Defer so sibling instances mounted in the same tick are attached to\n // the DOM before we query it.\n queueMicrotask(() => {\n if (!this.isConnected) return;\n const projectId = this.getAttribute(PROJECT_ID_ATTR);\n const flowId = this.getAttribute(FLOW_ID_ATTR);\n const key = `${projectId}|${flowId}`;\n // Bail before the DOM query when we've already warned for this\n // identity — connectedCallback can fire several times per element.\n if (\n this.#warnedForKey === key ||\n !isDuplicateSameFlowInstance(this)\n ) {\n return;\n }\n this.#warnedForKey = key;\n this.logger.warn(\n 'Multiple Descope flow components detected on the same page',\n `The same flow (\"${flowId}\") and project (\"${projectId}\") are running more than once on this page. This is not supported and may cause the flow to behave unexpectedly.`,\n );\n });\n }\n\n connectedCallback() {\n super.connectedCallback?.();\n this.#scheduleDuplicateFlowCheck();\n }\n\n // Re-check when the flow identity changes at runtime. BaseDescopeWc\n // forwards `super.attributeChangedCallback?.()`; the `#warnedForKey`\n // de-dupe keeps this to one warning even if it also fires on mount.\n attributeChangedCallback(\n attrName: string,\n oldValue: string,\n newValue: string,\n ) {\n super.attributeChangedCallback?.(attrName, oldValue, newValue);\n if (\n oldValue !== newValue &&\n (attrName === PROJECT_ID_ATTR || attrName === FLOW_ID_ATTR)\n ) {\n this.#scheduleDuplicateFlowCheck();\n }\n }\n };\n },\n);\n"],"names":["PROJECT_ID_ATTR","FLOW_ID_ATTR","getSameFlowInstances","el","projectId","getAttribute","flowId","Array","from","ownerDocument","querySelectorAll","filter","other","isDuplicateSameFlowInstance","sameFlow","length","duplicateFlowWarningMixin","createSingletonMixin","superclass","BaseClass","compose","loggerMixin","_a","constructor","_DuplicateFlowWarningMixinClass_warnedForKey","set","this","connectedCallback","_b","super","call","__classPrivateFieldGet","_DuplicateFlowWarningMixinClass_instances","_DuplicateFlowWarningMixinClass_scheduleDuplicateFlowCheck","attributeChangedCallback","attrName","oldValue","newValue","queueMicrotask","isConnected","key","__classPrivateFieldSet","logger","warn"],"mappings":"sMAIA,MACMA,EAAkB,aAClBC,EAAe,UAORC,EAAwBC,IACnC,MAAMC,EAAYD,EAAGE,aAAaL,GAC5BM,EAASH,EAAGE,aAAaJ,GAC/B,OAAKG,GAAcE,EACZC,MAAMC,KAAKL,EAAGM,cAAcC,iBAbd,eAagDC,QAClEC,GACCA,EAAMP,aAAaL,KAAqBI,GACxCQ,EAAMP,aAAaJ,KAAkBK,IAJP,EAKjC,EAUUO,EAA+BV,IAC1C,MAAMW,EAAWZ,EAAqBC,GACtC,OAAOW,EAASC,OAAS,GAAKD,EAAS,KAAOX,CAAE,EAUrCa,EAA4BC,GACFC,gBACnC,MAAMC,EAAYC,EAAQC,EAARD,CAAqBF,GAEvC,OAAOI,EAAA,cAA6CH,EAA7C,WAAAI,mCAKLC,EAAuBC,IAAAC,UAAA,EA+CxB,CArBC,iBAAAC,SACyB,QAAvBC,EAAAC,MAAMF,yBAAiB,IAAAC,GAAAA,EAAAE,KAAAJ,MACvBK,EAAAL,KAAIM,EAAA,IAAAC,GAAJH,KAAAJ,KACD,CAKD,wBAAAQ,CACEC,EACAC,EACAC,SAEiC,QAAjCT,EAAAC,MAAMK,gCAA2B,IAAAN,GAAAA,EAAAE,KAAAJ,KAAAS,EAAUC,EAAUC,GAEnDD,IAAaC,GACZF,IAAanC,GAAmBmC,IAAalC,GAE9C8B,EAAAL,KAAIM,EAAA,IAAAC,GAAJH,KAAAJ,KAEH,4CAzCCY,gBAAe,KACb,IAAKZ,KAAKa,YAAa,OACvB,MAAMnC,EAAYsB,KAAKrB,aAAaL,GAC9BM,EAASoB,KAAKrB,aAAaJ,GAC3BuC,EAAM,GAAGpC,KAAaE,IAI1ByB,EAAAL,KAAkBF,EAAA,OAAKgB,GACtB3B,EAA4Ba,QAI/Be,EAAAf,KAAIF,EAAiBgB,EAAG,KACxBd,KAAKgB,OAAOC,KACV,6DACA,mBAAmBrC,qBAA0BF,qHAC9C,GAEJ,EAuBDkB,CAAA"}