-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Static Site Generators #194
Comments
Hi @cgrail thanks for your issue. |
Hi @cgrail |
Just as an FYI - I've heard that Stencil.js is a good tool for compiling design systems into standard web component libraries that support, among other things, SSR. https://stenciljs.com/ |
Hi @petermuessig , When using the react web components in NextJS the way it is described in the documentation, I get the following error:
I didn't get into the technical details yet, but there is something going wrong on the SSR side.
https://nextjs.org/docs/advanced-features/dynamic-import This way I managed to use the components with NextJS. I think it wouldn't be a bad idea to consider diving into this issue since NextJS is a popular goto framework to develop React applications. Kr, |
HI @ThomasSwolfs , thanks for the feedback. I need to understand how this module is used in Next.js. It seems to be a more general issue which means that you are trying to use an ES6 module import outside an ES6 module. Where did you use this? In a naked Next.js boilerplate code? How is the module loaded which imports the Theme Provider? From what I see here is that the ThemeProvider is required (CommonJS) but an ES6 module cannot be required. Maybe I also misunderstand the issue here - then please forgive me... 😄 The dynamic import is doing the trick that ES6 modules can be imported in the non-ES6 module code, right? Maybe also @MarcusNotheis can take a look into this. Best regards, |
Hi @petermuessig , I think that you are right about the ES6 modules. I'm using a naked Next.js boilerplate indeed. I found a package https://www.npmjs.com/package/next-transpile-modules which tackles this issue and transpiles modules using ES6 modules. Now the next error is a quite logical one. Document is only available in a browser. So when Next.js tries to access the web components library, on the server side the code will crash. |
Hey @ThomasSwolfs, |
Hi Marcus, that's good news! |
Hey Thomas,
|
Hey Marcus, Is lazy loading the right way to go here? In my understanding, that's what next/dynamic is doing. Wouldn't this just be the same kind of workaround? I'm just spilling some uncertain thoughts here, so please correct me if I'm wrong. :-) |
I'm not sure to be honest. I think the approach you shared is the best way to do it in a import { ButtonDesign } from '@ui5/webcomponents-react/lib/ButtonDesign';
import { withWebComponent } from '@ui5/webcomponents-react/lib/withWebComponent';
import '@ui5/webcomponents/dist/Button';
/**
* <a href="https://sap.github.io/ui5-webcomponents/playground/components/Button" target="_blank">UI5 Web Components Playground</a>
*/
var Button = withWebComponent('ui5-button', ['design', 'icon'], ['disabled', 'iconEnd', 'submits'], [], ['click']);
Button.displayName = 'Button';
Button.defaultProps = {
design: ButtonDesign.Default,
disabled: false,
iconEnd: false,
submits: false
};
export { Button };
//# sourceMappingURL=Button.js.map Currently, line 3 ( |
Good point, I understand what you are saying. It will be a more generic solution indeed. I did a little research and found this repository: Maybe this option is overkill? I'm not really sure about the differences between both options in terms of performance etc.. |
Hey @ThomasSwolfs, I played around with SSR and Next.js and was able to achieve first results. We are now e.g. able to render a Best regards, |
Hey all, I was finally able to build a working Next.js app with the help of a custom babel plugin: https://github.com/MarcusNotheis/babel-plugin-ui5-webcomponents-react-nextjs Although you can build and run a Next.js app with that plugin, this doesn't really support Server Side Rendering because it will just transform all imports from webcomponents react into dynamic, client only imports. Having said that, I'll close this issue for now as I don't see any chance to get real SSR with Web Components - but we might come back to it later as soon as there is a general concept for rendering web components on server side available. Best regards, |
Thanks a lot for trying. |
I really like UI5 WebComponents for React. I wanted to use it in combination with a static site generator like Next.js or Gatsby.js, but it didn't work. I don't think Server Side Rendering is supported currently. Would be great if you could support that to improve the speed of the initial page loading.
The text was updated successfully, but these errors were encountered: