Skip to content

Commit bee00f3

Browse files
committed
Update component loader to support keeping script tags in views
1 parent 4a7108f commit bee00f3

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

public/js/router.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/**
22
* Router module for SPA navigation
33
*/
4-
import { Router, transitions, renderer } from 'https://esm.sh/@profullstack/[email protected]';
4+
import { Router, transitions, renderer, componentLoader } from 'https://esm.sh/@profullstack/[email protected]';
55
import { localizer } from './i18n-setup.js';
6-
import { detectAndImportModules, executeInlineScripts, filterScriptTags } from './utils/component-loader.js';
76
import {
87
initLoginPage,
98
initRegisterPage,
@@ -42,13 +41,13 @@ async function loadPage(url) {
4241
const doc = parser.parseFromString(html, 'text/html');
4342

4443
// Import any modules
45-
await detectAndImportModules(doc);
44+
await componentLoader.detectAndImportModules(doc);
4645

4746
// Execute any inline scripts
48-
await executeInlineScripts(doc);
47+
await componentLoader.executeInlineScripts(doc);
4948

50-
// Filter out script tags
51-
const contentWithoutScripts = filterScriptTags(doc.body);
49+
// Filter out script tags, but keep them for views
50+
const contentWithoutScripts = componentLoader.filterScriptTags(doc.body, true); // Keep script tags
5251
const content = contentWithoutScripts.innerHTML;
5352

5453
// Pre-translate the content
@@ -133,7 +132,8 @@ export function createRouter(options = {}) {
133132
transition: customFade,
134133
renderer: renderer.createRenderer({
135134
translateContainer: localizer.translateContainer.bind(localizer),
136-
applyRTLToDocument: localizer.applyRTLToDocument.bind(localizer)
135+
applyRTLToDocument: localizer.applyRTLToDocument.bind(localizer),
136+
keepScripts: true // Keep script tags in views
137137
}),
138138
errorHandler: (path) => {
139139
console.log('Custom error handler called for path:', path);

public/js/utils/component-loader.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ export async function executeInlineScripts(doc) {
9191
/**
9292
* Filters out script tags from HTML content
9393
* @param {HTMLElement} element - Element to filter scripts from
94-
* @returns {DocumentFragment} - Document fragment with scripts removed
94+
* @param {boolean} keepScripts - Whether to keep script tags in the output (default: false)
95+
* @returns {DocumentFragment} - Document fragment with scripts removed or preserved
9596
*/
96-
export function filterScriptTags(element) {
97+
export function filterScriptTags(element, keepScripts = false) {
9798
const tempDiv = document.createElement('div');
9899

99-
// Clone all child nodes except script tags
100+
// Clone all child nodes, optionally excluding script tags
100101
Array.from(element.children).forEach(child => {
101-
if (child.tagName !== 'SCRIPT') {
102+
if (keepScripts || child.tagName !== 'SCRIPT') {
102103
tempDiv.appendChild(child.cloneNode(true));
103104
}
104105
});

0 commit comments

Comments
 (0)