Note: This is an issue generated issue & code. I checked and approved everything.

Problem/Motivation

The Nuxt preview provider renders every editor component into a plain block div.nuxt-preview-container. (1) That div — not the component root — becomes the flex/grid item of any surrounding layout component, so the component's own layout classes never apply and the editor rendering diverges from the published page (which has no wrapper at all); %-based components collapse to min-content inside shrink-to-fit parents. (2) js/nuxt-preview.js mounts via document.querySelector('#' + id) although it already holds the element; editors that double-buffer preview documents (e.g. Drupal Canvas' iframe swap) have the same id in two documents, and queued mounts from a swapped-out document throw Target element not found — hundreds of console errors per editor load.

Steps to reproduce

Drupal Canvas + Nuxt preview provider; a page placing components inside a flex layout. Observe collapsed components in the editor (correct on the published page) and the console error flood on editor load.

Proposed resolution

Add css/nuxt-preview.css with .nuxt-preview-container { display: contents; } to the nuxt_preview library, so the component root participates in layout exactly as on the published page (pre-mount the container only holds visually-hidden slot elements; the error message it renders is a block box of its own).
In js/nuxt-preview.js, pass the container element itself to $previewComponent() (nuxt-component-preview accepts string|Element) and skip containers whose document was swapped out (!container.isConnected).
Patch attached (applies to 3.x and 3.4.1).

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

fago created an issue. See original summary.

fago’s picture

Status: Active » Needs review

ready

  • fago committed 41c2fcdb on 3.x
    task: #3615373 Nuxt preview: make the preview container layout-...
fago’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.