Skip to content

Commit f97049c

Browse files
committed
dialog fixes
1 parent 5f6b008 commit f97049c

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

astro.config.mjs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
import { 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+
326
export 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

src/components/Authors.astro

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff 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

src/components/SearchDialog.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
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

0 commit comments

Comments
 (0)