Skip to content

Commit

Permalink
Instantiate component enhancements on load event, not DOMContentLoaded
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyuly committed Oct 23, 2024
1 parent f1e39f6 commit 095c8fc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,12 @@ globalThis.ViewScript.components["${componentId}"]
const scriptData = JSON.stringify(componentData);

const minifiedScript = await minify(`
addEventListener("DOMContentLoaded", function () {
addEventListener("load", function () {
new (globalThis.ViewScript.components["${componentId}"].default)(${scriptData});
});`);

scriptElement.textContent = minifiedScript.code;
scriptElement.className = componentId;
dom.window.document.head.appendChild(scriptElement);
}

Expand All @@ -320,10 +321,6 @@ exports.getComponentFromFs = async function getComponentFromFs(

return cachedComponent;
}

console.log(
`[viewscript-server] getComponentFromFs ${componentDir} from disk`
);
}

const settingsFilePath = resolve(baseDir, componentDir, "settings.yaml");
Expand Down Expand Up @@ -352,6 +349,10 @@ exports.getComponentFromFs = async function getComponentFromFs(
getComponentFromFsCache.set(componentDir, component);
}

console.log(
`[viewscript-server] getComponentFromFs ${componentDir} from disk`
);

return component;
};

Expand Down Expand Up @@ -387,8 +388,8 @@ exports.renderComponent = async function renderComponent(

const componentContext = {
...context,
renderComponent,
componentSettings,
renderComponent,
};

applyDataToDomElement(
Expand Down

0 comments on commit 095c8fc

Please sign in to comment.