@lwrjs/client-modules
Advanced tools
Comparing version 0.0.2-alpha36 to 0.0.2-alpha37
@@ -0,1 +1,11 @@ | ||
// TODO: This is a temporal workaround until https://github.com/salesforce/lwc/pull/2083 is sorted | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import { createElement } from 'lwc'; | ||
function initializeWebComponent(elementName, Ctor) { | ||
return createElement(elementName, { | ||
is: Ctor | ||
}); | ||
} | ||
/** | ||
@@ -11,2 +21,4 @@ * Convert a module specifier into a valid CustomElement registry name: | ||
*/ | ||
function toKebabCase(specifier) { | ||
@@ -29,10 +41,9 @@ return specifier.replace(/\/v\/[a-zA-Z0-9-_.]+$/, '').replace('/', '-').replace(/([A-Z])/g, c => `-${c.toLowerCase()}`); | ||
// Kebab-case the specifier | ||
const elementName = toKebabCase(moduleSpecifier); // Add the root to the CustomElementRegistry | ||
const elementName = toKebabCase(moduleSpecifier); // Append the root element to the DOM, if it does not exist | ||
// this is for SPA like routes (one component at the root level) utilizing the lwr-root directive | ||
customElements.define(elementName, ctor.CustomElementConstructor); // Append the root element to the DOM, if it does not exist | ||
let el = document.body.querySelector(elementName); | ||
if (!el) { | ||
el = document.createElement(elementName); | ||
el = initializeWebComponent(elementName, ctor); | ||
@@ -46,2 +57,16 @@ if (container) { | ||
} | ||
} else { | ||
// We have rendered/ssred an HTML page and we need to reify the components | ||
// Due to the bug described on the header, for each custom element | ||
// we collect the attributes and we replace the element with the new synthetic contructor | ||
const customElements = document.querySelectorAll(elementName); | ||
customElements.forEach(customElement => { | ||
const newElement = initializeWebComponent(elementName, ctor); | ||
for (const attr of customElement.attributes) { | ||
newElement.setAttributeNode(attr); | ||
} | ||
customElement.parentElement.replaceChild(newElement, customElement); | ||
}); | ||
} | ||
@@ -48,0 +73,0 @@ }); |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.0.2-alpha36", | ||
"version": "0.0.2-alpha37", | ||
"homepage": "https://lwr.dev/", | ||
@@ -35,3 +35,3 @@ "repository": { | ||
"@locker/sandbox": "^0.12.2", | ||
"@lwrjs/shared-utils": "0.0.2-alpha36" | ||
"@lwrjs/shared-utils": "0.0.2-alpha37" | ||
}, | ||
@@ -54,3 +54,3 @@ "lwc": { | ||
}, | ||
"gitHead": "90780d8ce526e05385aa60f74bf86cd1716268e8" | ||
"gitHead": "499acedb8f2dabcb2a1f5dc303dd3efe459de414" | ||
} |
Sorry, the diff of this file is too big to display
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
206688
9
4635
+ Added@lwrjs/shared-utils@0.0.2-alpha37(transitive)
- Removed@lwrjs/shared-utils@0.0.2-alpha36(transitive)