File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { defineConfig } from "astro/config" ;
22
3+ // Prevent duplicate customElements.define() errors in dev mode.
4+ // The myst-awesome library imports Web Awesome components from many
5+ // separate <script> entry points, which Astro/Vite can execute more
6+ // than once. This patches define() to silently skip duplicates.
7+ function safeCustomElements ( ) {
8+ return {
9+ name : "safe-custom-elements" ,
10+ hooks : {
11+ "astro:config:setup" ( { injectScript } ) {
12+ injectScript (
13+ "head-inline" ,
14+ `{
15+ const orig = customElements.define.bind(customElements);
16+ customElements.define = function (name, ctor, opts) {
17+ if (!customElements.get(name)) orig(name, ctor, opts);
18+ };
19+ }`
20+ ) ;
21+ } ,
22+ } ,
23+ } ;
24+ }
25+
326export default defineConfig ( {
427 // Use the myst-awesome theme configuration
5- integrations : [ ] ,
28+ integrations : [ safeCustomElements ( ) ] ,
629
730 server : {
831 port : 4321 , // Use port 4321 for the main project
Original file line number Diff line number Diff line change @@ -179,9 +179,7 @@ if (authors) {
179179)}
180180
181181<script >
182- // Web Awesome icons are loaded globally
183- // Import Web Awesome components
184- import '@awesome.me/webawesome/dist/components/icon/icon.js';
182+ // Web Awesome icon component is loaded by BasePage layout
185183 import { registerScienceIconsLibrary } from '@awesome-myst/myst-awesome/lib/wa-scienceicons.ts';
186184
187185 // Register scienceicons library
Original file line number Diff line number Diff line change 3838
3939<script >
4040 // @ts-nocheck
41+ // Web Awesome icon/button components are loaded by BasePage layout
4142 import '@awesome.me/webawesome/dist/components/dialog/dialog.js';
4243 import '@awesome.me/webawesome/dist/components/input/input.js';
43- import '@awesome.me/webawesome/dist/components/icon/icon.js';
4444 import '@awesome.me/webawesome/dist/components/zoomable-frame/zoomable-frame.js';
4545 import Fuse from 'fuse.js'
4646
You can’t perform that action at this time.
0 commit comments