qwik
qwik copied to clipboard
SSR | OnGet | UseEndpoint.resolved
Qwik Version
"@builder.io/qwik": "0.0.105",
Operating System (or Browser)
all
Node Version (if applicable)
No response
Which component is affected?
Qwik City
Expected Behaviour
Previously this problem has not been solved
ES: Anteriormente este problema no ha podido ser resuelto
Actual Behaviour
We want to render according to the header of the request two different components (for example), one for desktop and one for mobile, by default in the store we mark to render the mobile, this causes a choice issue on desktop devices due to the order of execution. Given the:
- onGet -> store default value mobile -> render mobile component
- useEndpoint.resolved -> store changes value to desktop -> render desktop component
ES: Queremos renderizar según el encabezado de la solicitud dos componentes diferentes (por ejemplo), uno para escritorio y otro para móvil, por defecto en la store marcamos para renderizar el móvil, esto provoca un problema de elección en los dispositivos de escritorio debido al orden de ejecución. Dado que:
- onGet -> se define en la store el valor móvil como predeterminado -> renderizar componente móvil
- useEndpoint.resolved -> la store altera el valor a escritorio -> renderizar componente de escritorio
Additional Information
example repo:
https://github.com/devagja/qwik-ssr-headers
Is it possible to execute the promise in the store declaration?
In this way we would set the default value of the store with the result of the execution of the server directly
ES: ¿es posible de alguna forma ejecutar la promesa en la declaracion del store ?
De esta forma el default value de la store sería el resultado de la ejecución del servidor directamente
I think what you want can be achieved by setting up a store with an undefined value, and then writing to the store in the <Resource>
's onResolved
handler?
How about ?
const resource = useEndpoint<typeof onGet>();
const store = useStore({
value: null,
});
useServerMount$(async () => {
store.value = await resource.promise;
});
Yes I think @petebacondarwin suggestion would work: https://github.com/BuilderIO/qwik/issues/1164#issuecomment-1266559329