Skip to content

Commit 9da9dd2

Browse files
author
Fergus Bisset
committed
fix(HeaderServer): add type="module" to inline script for ES6 import support
- Add type="module" attribute to inline script tag in HeaderServer - Remove unnecessary typeof import check (always available in modules) - Fixes "Cannot use import statement outside a module" error in Next.js The inline script was using dynamic import() which requires ES6 module context. Without type="module", browsers treat inline scripts as classic scripts which don't support import statements.
1 parent a831a5c commit 9da9dd2

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/components/Header/Header.render.server.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ export function renderHeaderMarkupServer(
290290
</header>
291291
{/* SSR-safe behaviour initialization: inline script runs only in browser */}
292292
<script
293+
type="module"
293294
dangerouslySetInnerHTML={{
294295
__html: `
295296
(function() {
@@ -304,17 +305,15 @@ export function renderHeaderMarkupServer(
304305
// Wait for DOM ready and behaviour module to be available
305306
function initHeader() {
306307
// Dynamic import for behaviour module
307-
if (typeof import !== 'undefined') {
308-
import('/dist/behaviours/headerBehaviour.js')
309-
.then(function(mod) {
310-
if (mod && mod.initHeaders) {
311-
mod.initHeaders(header);
312-
}
313-
})
314-
.catch(function(err) {
315-
console.warn('Failed to initialize header behaviour:', err);
316-
});
317-
}
308+
import('/dist/behaviours/headerBehaviour.js')
309+
.then(function(mod) {
310+
if (mod && mod.initHeaders) {
311+
mod.initHeaders(header);
312+
}
313+
})
314+
.catch(function(err) {
315+
console.warn('Failed to initialize header behaviour:', err);
316+
});
318317
}
319318
320319
// Initialize after DOM is ready

0 commit comments

Comments
 (0)