Server Side Rendering
To enable SSR
you should provide the --ssrEnabled
flag. With this flag Ragu will start to return the micro-frontend
HTML rendered from server.
- Yarn
- NPM
After you activate the flag you will see a tiny difference into the micro-frontend's manifest file.
When SSR
is enabled, Ragu's manifest returns the html
property which is the result of your application.
#
The state fileLet's say you want your micro-frontend to perform an async operation, fetching a request for example. You can use a state file for this purpose. A state file is only executed from the server side, that means that the browser will never perform that action. Also, the state will be passed as a property to your micro-frontend.
The state file must export a default function that returns a Promise
.
Properties received by the state
function are the same described at
Micro-frontend API.
The result will be provided to your micro-frontend as a query parameter.
It is important to know that the state function is always resolved at the server side. That means that the PokéAPI
call will never be performed at the browser.
#
Executing the state file- Yarn
- NPM
Open the preview route providing the number parameter: http://localhost:3100/preview?number=1
Let's take a look at the manifest file: http://localhost:3100/?number=1.
The state file is there and that's how Ragu transits information between the server and client-side.
info
The state mechanism is the same for any framework. There always will be a state file, also the state will be provided by props at the micro-frontend function.
Code Example
The example above can be found here