Skip to content

Instantly share code, notes, and snippets.

@fago
Created April 14, 2026 11:59
Show Gist options
  • Select an option

  • Save fago/712ebf94be0bcb987de4535672b97e3a to your computer and use it in GitHub Desktop.

Select an option

Save fago/712ebf94be0bcb987de4535672b97e3a to your computer and use it in GitHub Desktop.
diff --git a/js/nuxt-app-loader.js b/js/nuxt-app-loader.js
new file mode 100644
index 0000000..eabbd9b
--- /dev/null
+++ b/js/nuxt-app-loader.js
@@ -0,0 +1,28 @@
+/**
+ * @file
+ * Loads the Nuxt app-loader script for component preview.
+ *
+ * Runs immediately in <head> (no Drupal behavior) so the Nuxt app starts
+ * bootstrapping during HTML parsing, before footer JS loads.
+ *
+ * Sets window.__nuxtComponentPreviewFailed on error so the nuxt-preview
+ * behavior can show per-component error messages.
+ */
+
+((drupalSettings) => {
+ const baseUrl = drupalSettings?.customElementsNuxtPreview?.baseUrl;
+ if (!baseUrl) {
+ return;
+ }
+
+ const script = document.createElement('script');
+ script.src = `${baseUrl}/nuxt-component-preview/app-loader.js`;
+ script.setAttribute('data-cdn-url', baseUrl);
+ script.setAttribute('data-build-assets-dir', '/_nuxt/');
+
+ script.onerror = () => {
+ window.__nuxtComponentPreviewFailed = true;
+ };
+
+ document.head.appendChild(script);
+})(drupalSettings);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment