Hi Team, Need your help for adding support for Ang...
# ask-a-descoper
s
Hi Team, Need your help for adding support for Angular SSR, please find the details below. Descope Angular SDK SSR Compatibility Issue Problem Summary The
@descope/angular-sdk
package (version 0.21.11) is not compatible with Angular Server-Side Rendering (SSR) due to the underlying
@descope/web-component
package attempting to register custom elements during module initialization. Error Details Error Message:
Copy code
ReferenceError: customElements is not defined
    at 67077 (/path/to/dist/xyz/server/vendor.js:7609:1)
Root Cause: The
@descope/web-component
package (version 3.49.0) executes the following code at module load time:
Copy code
customElements.get('descope-wc')
  ? console.log('descope-wc is already defined')
  : customElements.define('descope-wc', DescopeWc);
loading from https://github.com/descope/angular-sdk/blob/main/projects/angular-sdk/src/lib/components/descope/descope.component.ts >> https://github.com/descope/descope-js/blob/main/packages/sdks/web-component/src/lib/descope-wc/index.ts This code runs during server-side bundle compilation/execution where the
customElements
API (a browser-only Web Components API) is not available. Environment • Framework: Angular 17.3.2 with SSR • Descope SDK Version: @descope/angular-sdk@0.21.11 • Web Component Version: @descope/web-component@3.49.0 (transitive dependency) • Node.js Version: v22.19.0 • Build Tool: Angular CLI with Webpack bundling Recommended Solutions Option 1: Lazy/Deferred Custom Element Registration (Recommended) Modify
@descope/web-component
to defer custom element registration until it's actually needed, rather than at module load time:
Copy code
// Instead of immediate registration:
// customElements.define("descope-wc", DescopeWc);

// Use lazy registration:
export function registerDescopeWc() {
  if (
    typeof customElements !== 'undefined' &&
    !customElements.get('descope-wc')
  ) {
    customElements.define('descope-wc', DescopeWc);
  }
}

// Or check for browser environment:
if (typeof window !== 'undefined' && typeof customElements !== 'undefined') {
  customElements.define('descope-wc', DescopeWc);
}
Option 2: Environment Detection Add environment detection to prevent registration in Node.js/SSR contexts:
Copy code
const isBrowser =
  typeof window !== 'undefined' && typeof customElements !== 'undefined';
if (isBrowser && !customElements.get('descope-wc')) {
  customElements.define('descope-wc', DescopeWc);
}
Option 3: Separate Browser/Server Builds Provide separate entry points or builds for browser and server environments, similar to how many libraries handle SSR compatibility. Option 4: Dynamic Import Support Support dynamic imports for the web component, allowing Angular SSR users to load it only in the browser:
Copy code
// In Angular component
if (isPlatformBrowser(this.platformId)) {
  await import('@descope/web-component');
}
Impact • Current Impact: Blocks SSR builds from completing successfully • User Impact: Prevents deployment of Angular applications using Descope with SSR enabled Requested Action Please update
@descope/angular-sdk
to: 1. Check for browser environment before registering custom elements 2. Defer registration until the component is actually used 3. Provide SSR-safe initialization patterns Alternatively, provide official SSR compatibility guidance and/or a server-safe build variant. Related Issues This issue affects any Angular application using: • Angular Universal / SSR • Server-side rendering • Static site generation (SSG) • Any build process that evaluates modules in a Node.js environment Date: 08/12/2025 SDK Version: @descope/angular-sdk@0.21.11 Web Component Version: @descope/web-component@3.49.0
r
Looping @Meir Wahnon here.
Hi @Srujan Purohit Please open feature request for this.
s
@Rahul Rijhwani https://ideas.descope.works/p/add-support-for-angular-ssr. What's the general turn around time and ETAs for feature requests?
n
@Asaf Shen any insight on this?
a
Im not an angular expert but here are some insights • the web-component , which is used by Descope module , is client side component, and could not render on server (by design, it is built that way) • You may be able to work around this with lazy loading the Descope component yourself in your code
s
@Asaf Shen tried that, but it is will not work as this is coming from root level import,
DescopeAuthModule
(imported as root config for interceptor, services etc) >>
./components/descope/descope.component
>>
@descope/web-component.
Let me know if we need to connect over call.
a
I am not sure I would be able to provide more details on a call, maybe you can lay load the
DescopeAuthModule
s
nop. you can't. That needs to be initialised at root level as stated in the doc also. because we need to set initializeApp and descopeInterceptor which can only be done at root level
@Asaf Shen any update here?
a
I actually don't have any update or a hint how to solve this, let me convey this requirement internally
s
Okay. Any ETA?
a
Hi, not yet, we are still lookin into this