Skip to content

Commit

Permalink
Fix: load all components at the right time
Browse files Browse the repository at this point in the history
After first paint, but before the data is required by other things!
  • Loading branch information
jobelenus committed Dec 18, 2024
1 parent 9796322 commit 0dd1172
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
18 changes: 0 additions & 18 deletions app/web/src/store/components.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1399,29 +1399,11 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
],
);

realtimeStore.subscribe(
`${this.$id}-workspace`,
`workspace/${workspaceId}`,
[
{
eventType: "ChangeSetApplied",
callback: (data) => {
// If the applied change set has rebased into this change set,
// then refetch (i.e. there might be updates!)
if (data.toRebaseChangeSetId === changeSetId) {
this.FETCH_ALL_COMPONENTS();
}
},
},
],
);

const actionUnsub = this.$onAction(handleStoreError);

return () => {
actionUnsub();
realtimeStore.unsubscribe(`${this.$id}-changeset`);
realtimeStore.unsubscribe(`${this.$id}-workspace`);
};
},
},
Expand Down
8 changes: 5 additions & 3 deletions app/web/src/store/views.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,14 +642,15 @@ export const useViewsStore = (forceChangeSetId?: ChangeSetId) => {
this.recentViews.push(id);
},
async LIST_VIEWS(all = false) {
await componentsStore.FETCH_ALL_COMPONENTS();

return new ApiRequest<ViewDescription[]>({
method: "get",
url: API_PREFIX,
onSuccess: async (views) => {
this.viewList = views;
this.SORT_LIST_VIEWS();
if (!all)
// e.g. initial page load
await componentsStore.FETCH_ALL_COMPONENTS();
for (const { id } of views) {
// assuming we're coming from "on load", we have the FETCH that gets the selectedViewId
if (all || id !== this.selectedViewId)
Expand All @@ -666,6 +667,7 @@ export const useViewsStore = (forceChangeSetId?: ChangeSetId) => {
});
},
async FETCH_VIEW_GEOMETRY(viewId: ViewId) {
// requires all components to be in place!
return new ApiRequest<{
viewId: ViewId;
name: string;
Expand Down Expand Up @@ -701,7 +703,6 @@ export const useViewsStore = (forceChangeSetId?: ChangeSetId) => {
([componentId, geo]) => {
const node = componentsStore.allComponentsById[componentId];
if (!node) return;
if (!view) return; // no idea why linting is complaining that i need this
let geometry: IRect;
if ("width" in node) {
geo.width = node.width;
Expand Down Expand Up @@ -1963,6 +1964,7 @@ export const useViewsStore = (forceChangeSetId?: ChangeSetId) => {
// If the applied change set has rebased into this change set,
// then refetch (i.e. there might be updates!)
if (data.toRebaseChangeSetId === changeSetId) {
await componentsStore.FETCH_ALL_COMPONENTS();
this.LIST_VIEWS(true); // loads all other view data
}
},
Expand Down

0 comments on commit 0dd1172

Please sign in to comment.