Skip to content

live-preview: preview iframe stays empty with ng serve since 51.7.0/51.8.0 (import.meta.url resolves into Vite's pre-bundle cache) #3303

In progress

Description

@Chreggii

Prerequisites

  • I have read the Contributing Guidelines.
  • I have not leaked any internal/restricted information like screenshots, videos, code snippets, links etc.

Affected component

Summary

After updating @siemens/live-preview from 51.6.0 to 51.8.0, the example preview no longer renders when using the Angular dev server (ng serve). The navigation panel works, but the example area in the middle stays empty. Production builds aren't affected.

Suggested fix

Resolve the application URL from the host document, for example new URL('.', document.baseURI), or make it configurable through SiLivePreviewConfig. Use import.meta.url only where module-relative resolution is really needed, such as embeddable elements loaded cross-origin.

Version

  • @siemens/live-preview 51.8.0 (works with 51.6.0)
  • Angular 22.2.3, ng serve (Vite 8 dev server, dependency pre-bundling enabled by default)
  • pnpm

Steps to reproduce

  1. Set up live preview as documented (SimplLivePreviewModule.forRoot({ componentLoader, examplesBaseUrl: 'app/examples/', ... }) with livePreviewRoutes).
  2. Run ng serve and open an example.

Code reproduction example

...

What is the current bug behavior

The iframe src points into Vite's dependency cache instead of the application root:

http://localhost:4200/@fs/<project>/.angular/cache/22.2.3/<app>/vite/deps/#/iframe?parentOrigin=...

Inside the iframe, main.js, polyfills.js and styles.css return 404, so the example never boots.

LivePreviewUrlService works out the application URL from the location of its own module:

// Keep resolution at runtime to avoid Vite rewriting '.' as a filesystem asset.
applicationUrl = new URL('.', new URL(import.meta.url));
iframeUrl = this.routeUrl('iframe', ...);
examplesBaseUrl = new URL(this.config.examplesBaseUrl, this.applicationUrl).href;

With Vite dependency pre-bundling, import.meta.url is .../.angular/cache/.../vite/deps/@siemens_live-preview.js, so applicationUrl, and with it iframeUrl and examplesBaseUrl, resolve to the cache folder.

In 51.6.0 the iframe used a relative src="#/iframe", which always resolved against the host page. This probably came in with "live-preview: expose embeddable preview elements" (81e7728) in 51.7.0.

There's no config option to override the application URL, and LivePreviewUrlService isn't exported, so consumers can't fix it through DI.

What is the expected correct behavior

When running the app with the Angular dev server (ng serve), the live preview should render the selected example in the preview area, as it did in 51.6.0 and as it does in production builds.

Specifically:

  • The preview iframe should load the application root, e.g. http://localhost:4200/#/iframe?parentOrigin=..., not a path inside Vite's dependency cache (.../.angular/cache/.../vite/deps/#/iframe?...).
  • main.js, polyfills.js and styles.css should load inside the iframe without 404 errors, and the example component should boot and be displayed.
  • examplesBaseUrl should resolve against the application root, so example sources (template/TypeScript tabs) load correctly.
  • This should work with Vite's default dependency pre-bundling enabled, without needing prebundle.exclude for @siemens/live-preview in angular.json.

Activity

  1. reto-siemens commented on Nov 27, 2026

    @reto-siemens

    We hit the same root cause in a production build, not only with ng serve: when the app is served via GitLab job-artifact browsing (…/-/jobs/<id>/artifacts/public/index.html), new URL('.', import.meta.url) resolves to …/artifacts/public/, so the iframe requests …/artifacts/public/#/iframe?…. The artifact browser doesn't serve index.html for directory URLs, so that request returns 404. Note that the suggested new URL('.', document.baseURI) would still fail here; route URLs (iframe, viewer/...) should keep the document file name, e.g. build them from document.location.href with only the hash replaced, as the relative src="#/iframe" in 51.6.0 effectively did.

    image
  2. panch1739 commented on Dec 1, 2026

    @panch1739
    Member

    @spike-rabbit could you maybe take a look here? :)

  3. spike-rabbit commented on Dec 1, 2026

    @spike-rabbit
    Member

    @Chreggii / @reto-siemens can you please verify that #3357 would solve your issue. For me everything looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions