You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, we have access to data and onBeforeRender on the SSR pass, but we don't have a way to execute code before the hydration pass. This limits the ability to hydrate stores and forces us to do additional render passes.
example:
onBeforeRender(pageContext) {
const { data } = pageContext;
let initialStore = createStore(initialData);
if (!pageContext.isClientSideNavigation) {
hydrateStore(mapData(data));
return {
initialStore: serializeStore(initialStore)
}
}
}
Ideally, the store would be already hydrated before the hydration pass. This could be achieved by adding a custom hook such as +onBeforeHydration.
For my use case, making this a simple hook with a signature like `(pageContext) => void) would suffice, but for ergonomics, I think this could/should also work as a middleware, support async, and return pageContext.
For my example, this would look like:
import { store } from '../stores/store';
onBeforeHydration(pageContext) {
hydrateStore(store, pageContext.initialStore)
}
Currently, we have access to data and onBeforeRender on the SSR pass, but we don't have a way to execute code before the hydration pass. This limits the ability to hydrate stores and forces us to do additional render passes.
example:
Then on the client side:
Ideally, the store would be already hydrated before the hydration pass. This could be achieved by adding a custom hook such as
+onBeforeHydration
.For my use case, making this a simple hook with a signature like `(pageContext) => void) would suffice, but for ergonomics, I think this could/should also work as a middleware, support async, and return pageContext.
For my example, this would look like:
and an async use case
This would be similar, if not the same as #96
It may also help solve #87 and #57.
The text was updated successfully, but these errors were encountered: