Skip to content
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

Fix UIApiProvider state flow and hooks (for SSR) #224

Open
elbakerino opened this issue Feb 18, 2023 · 0 comments
Open

Fix UIApiProvider state flow and hooks (for SSR) #224

elbakerino opened this issue Feb 18, 2023 · 0 comments
Labels
bug Something isn't working core
Projects

Comments

@elbakerino
Copy link
Member

this was reported in a Slack chat, not reproducible for me, normal web-apps work because of a race-condition

expected that NextJS / remix stacks also produce the issue, it was reported with some custom built SSR

Current Behavior

The schemas are loaded on client-side but the hooks do no longer process the state updates correctly, thus always displaying Loading....

Reloading the page (when using localStorage cache) renders the schema as expected.

Expected Behavior

The schema loading should work on both sides, even when not "loading & injecting" on server, the schema should be loaded directly in client-side and rendered directly.

Each schema must only be loaded once - even when referenced multiple times in the same root-schema.

Optiomal solution would offer an option, that schemas are pre-loaded on server and no further loading in client is required.

Solution

The general problem is how useSchemaRef tries to load schemas, this currently only works because of some multiple renderings in client-side - but I expect (as far as I understand SSR) that the useRef/useMemo is re-hydrated with the latest values from server, thus it does not correctly process the actual state-reflow.

With some better state-listening inside useSchemaRef / somehow connecting the promise may allow to solve it.

  1. the loadSchema in useSchemaRef is not using a promise
  2. the loadSchema from UIApiProvider should actually work correctly
  3. the loadSchema from useSchemaNetworkRef does "drop the Promise"

Returning a promise in useSchemaNetworkRef makes it possible to introduce a correct state-listening / refresh inside useSchemaRef.

It most likely will still "not load the schema on server", but it should work correctly in browser "loading schemas once after initial render".

To allow preloading from server, it may need some Supense compatible info - or something else. This would be the optimal solution, which may need to wait till v0.5.x.

Your Environment

Tech Version
UI-Schema v0.4.5
@elbakerino elbakerino added bug Something isn't working core labels Feb 18, 2023
@elbakerino elbakerino added this to To do in ui-schema via automation Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core
Projects
ui-schema
  
To do
Development

No branches or pull requests

1 participant