Skip to content

Commit

Permalink
fix: lazy react exports (#320)
Browse files Browse the repository at this point in the history
This change "may" break some React setups that works with Webpack and specific React versions. Please inform us if you notice any problems.
  • Loading branch information
olkeoguz authored Dec 6, 2022
1 parent f1d49f9 commit d0d0d0b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"dependencies": {
"@floating-ui/dom": "^0.5.4",
"@fontsource/rubik": "^4.5.9",
"@lit-labs/react": "^1.0.7",
"@lit-labs/react": "^1.1.0",
"@open-wc/form-control": "^0.4.1",
"@open-wc/form-helpers": "^0.1.2",
"element-internals-polyfill": "^1.1.15",
Expand Down
24 changes: 14 additions & 10 deletions scripts/generate-react-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ function writeBaklavaReactFile(fileContentParts) {
${fileContentParts.join('\n\n')}
`;

fs.writeFileSync(
`${__dirname}/../src/baklava-react.ts`,
fileContentText.trim()
);
fs.writeFileSync(`${__dirname}/../src/baklava-react.ts`, fileContentText.trim());
}

function getReactEventName(baklavaEventName) {
Expand Down Expand Up @@ -48,12 +45,19 @@ for (const module of customElementsModules) {

baklavaReactFileParts.push(
`
export const ${componentName} = createComponent<${Type}>(
React,
'${fileName}',
customElements.get('${fileName}'),
${JSON.stringify(eventNames)}
);`
export const ${componentName} = React.lazy(() =>
customElements.whenDefined('${fileName}').then(elem => ({
default: createComponent<${Type}>(
{
react: React,
tagName: '${fileName}',
elementClass: elem,
events:${JSON.stringify(eventNames)}
}
)
})
));
`
);
}

Expand Down

0 comments on commit d0d0d0b

Please sign in to comment.