SAP / luigi

Micro frontend framework
https://luigi-project.io
Apache License 2.0
824 stars 170 forks source link

Usage with next.js #1122

Closed damianesteban closed 4 years ago

damianesteban commented 4 years ago

Description

This may turn into a Feature Request. I'm wondering if anyone has used luigi with next.js. I see instructions for a "regular" React.js app. One immediate issue I see is that next.js has its own router.

Reasons

We would like to use Luigi with next.js

Attachments

n/a

Thank you!

JohannesDoberer commented 4 years ago

Hello, thank you for the issue. We will take a look how to luigifying an app using next.js. Did you already find some issues?

Best regards

JohannesDoberer commented 4 years ago

Did you see our react example using luigi? I see that next.js is based on react. React has its own browser as well. https://github.com/SAP/luigi/blob/master/core/examples/luigi-example-react/src/index.js

Cheers

damianesteban commented 4 years ago

Yes, the difference is that Next.js can be server-side rendered. Can server-side apps use Luigi as well?

maxmarkus commented 4 years ago

Since we rely on the window object for LuigiClient as well as postMessage for all the APIs, I think you would need to take some extra steps to get things right. Guess a wrapper for LuigiClient would be required that only gets instantiated on client side, with an mock implementation for SSR. Just a feeling, but I have not tried SSR with Luigi yet.

damianesteban commented 4 years ago

Since we rely on the window object for LuigiClient as well as postMessage for all the APIs, I think you would need to take some extra steps to get things right. Guess a wrapper for LuigiClient would be required that only gets instantiated on client side, with an mock implementation for SSR. Just a feeling, but I have not tried SSR with Luigi yet.

Interesting. Often times with Next.js we have to mock the window object.

I'm going to give this a shot when I have some time and I'll get back to you. Luigi looks a great project and I would love if we could use it, and if other folks using SSR could use it as well.

JohannesDoberer commented 4 years ago

Hello Damian, I played around with nextjs and it is possible to write microfrontends in nextjs by using LuigiClient. That means you can register nextjs microfrontend's in a Luigi Core app and they can communicate with the core. This is possible.

That's probably not what you want, right? I guess you want to run a Luigi Core app based on nextjs, right? Currently I'm struggling how to change the root welcome page (index.html) in next js that the server is listing to sampleapp.html like in our react example. I think that the router of nextjs isn't an issue because react has it's own router as well.. but it's just a guess.

damianesteban commented 4 years ago

Oh wow I didn’t see this until now. Excellent. We will try it out and see how it is. Thanks so much.