Fix multiple definition fetch issue
Hello. I updated codes to show multiple items in Workspace when the API returns multiple terms/types. This will fix https://github.com/unisonweb/ui-core/issues/68
You can try it in the storybook with mocked API responses. However, I haven't tested it with actual UCM.
With Storybook, you can try with these buttons
I have updated the codebase, now it works to some extent. However, I found a bug.
After opening PositiveInt2, when you click the link to type PositiveInt2in the term declaration, it tries to fetch the definition infinitely somehow. I tried to debug it, but quite difficult. Were there similar issues before?
@yoching thanks for taking this on! I haven't seen that infinite loop bug before. Any thoughts on how we might attempt to verify it on Share (I'm not sure where PositiveInt2 is from?)
I found it! It doesn't seem to loop for me on Share: https://share.unison-lang.org/@kristiannotari/psql/code/main/latest/terms/examples/API/types/PositiveInt2
@hojberg The infinite fetch happens after this change. I'm testing local-ui with ui-core on this branch.
I found the reason for the loop request:
With new logic, it makes References of new items in workspaceItems based on the API response. A reference used for request (and loading state) is removed when handling FetchItemFinished.
However, a reference in App.Model.page, which is set by UrlChanged event, keeps being the reference used for request, and in this condition below, it goes to else case, then sending the same request again.
https://github.com/yoching/ui-core/blob/fix-multiple-definition/src/Code/Workspace.elm#L410-L412
It seems to make sense to make references based on the API response for items in workspaceItems, as API might response with multiple items for one request (not handling this was the source of the original issue #68).
One of the potential issues might be here in local-ui: https://github.com/unisonweb/unison-local-ui/blob/main/src/UnisonLocal/Page/CodePage.elm#L131-L137
Regardless of the Msg sent, it's calling updateSubpage, leading to the call of Workspace.open. It might be better to change the logic based on Msg received.
This is where reference is constructed based on API response https://github.com/unisonweb/ui-core/pull/90#discussion_r1621271414
Working on this issue, might take a bit more
Ah yeah I've dealt with loops from updateSubpage, its not fun!
Fixed loop fetch issue with a different approach!
I cleaned some decoding logic for clarity.
Also, can you check this PR on ui-core-scripts too? I've already been using this, but it's helpful to debug ui-core changes with local-ui. Thx! https://github.com/unisonweb/ui-core-scripts/pull/2
@hojberg It seems UI.Switch is not used anymore, which triggers the Elm review error on CI. Is it ok to remove it from codebase?
@yoching yeah I think thats good to remove. Sorry for sitting on this PR for so long. Lets get this passing and merged
Hello. I've removed UI.Switch. I think it's ready for review. I also have an open PR here: https://github.com/unisonweb/ui-core-scripts/pull/2, but it seems local-ui doesn't work with latest ui-core anymore?
Thank you @yoching !! Sorry for taking so long to get this merged. local-ui is meant to continue to work with ui-core, though it will soon be replaced by https://github.com/unisonweb/ucm-desktop