Fix slides org switching and form creation UX#2285
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Visual recap — skippedThe visual recap job did not run for this pull request. This is informational only and does not block the PR. Recap skipped for |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Builder reviewed your changes and found 1 potential issue 🟡
Review Details
Incremental Code Review Summary
The latest commit addresses the prior ordinary-route regression by flushing pending saves for normal unmounts and canceling only when the provider is marked as an organization-switch unmount. The added tests cover the committed loading, organization remount, and marker behavior. The previously reported ordinary-unmount cancellation comment was verified fixed and resolved.
Key Finding
- 🟡 MEDIUM — The new org-switch marker is written to a module-global counter during render. If React starts and abandons/replays a concurrent render before commit, the marker can remain even though no provider cleanup occurred. A later ordinary unmount may consume that stale marker and cancel pending edits instead of flushing them, causing unrelated data loss.
The existing organization-switch pending-edit concern remains a separate open issue and is not reposted. Both app servers were healthy, but browser executors again lacked Chrome automation tools, so runtime verification was unavailable.
🧪 Browser testing: Attempted after this review; skipped because browser automation tooling was unavailable (dev server was running).
| if (prevScopeRef.current !== organizationScope) { | ||
| // Org scope changed: signal that the imminent DeckProvider unmount is an | ||
| // org switch so its cleanup cancels pending ops instead of flushing them. | ||
| // This runs during render (synchronously before React's commit phase), which | ||
| // guarantees the flag is set before the DeckProvider cleanup executes. | ||
| markOrgSwitchUnmount(); | ||
| prevScopeRef.current = organizationScope; |
There was a problem hiding this comment.
🟡 Do not record organization-switch cleanup during render
markOrgSwitchUnmount() mutates a module-global counter during render, but React may start and abandon or replay a concurrent render before the keyed provider commits its unmount. That can leave a stale marker behind; a later ordinary provider unmount may consume it and cancel pending saves instead of flushing them. Move the bookkeeping to a commit-phase mechanism and associate it with the specific provider cleanup rather than a global render-time counter.
Additional Info
Reported independently by 1 of 2 code-review agents; latest tests cover only committed synchronous rerenders.
Summary
Fixes stale slide decks when switching organizations, and improves form creation UX with loading states and a corrected copy-link button.
Problem
In
templates/slides, switching organizations did not refresh the deck list — slides from the previous organization stayed visible until a manual page refresh. Intemplates/forms, creating a new form navigated to a randomly generated temporary ID before the form actually existed, causing a "Failed to load form" error page, and the copy-link button in the form builder toolbar was shown (but disabled/unclickable) for unpublished forms, which was confusing.Solution
OrganizationScopedDeckProviderthat remounts theDeckProviderwhenever the active organization changes, ensuring deck state is reset per-organization.Key Changes
OrganizationScopedDeckProvider.tsxintemplates/slides/app/context, which keysDeckProvideron${version}:${organizationScope}usinguseOrg()to force a remount on org change, plus a test verifying the remount behavior.templates/slides/app/root.tsxto useOrganizationScopedDeckProviderinstead ofDeckProviderdirectly in both the bare and full app layouts.templates/forms/app/components/layout/Sidebar.tsxandtemplates/forms/app/pages/FormsListPage.tsx: removed premature navigation using a random temp ID, navigate only inonSuccessofcreateForm.mutate, and added anIconLoader2spinner plusdisabledstate on the create button whilecreateForm.isPending.templates/forms/app/pages/FormBuilderPage.tsx: the copy public link button/tooltip is now only rendered whenform.status === "published", removing the disabled state and status-conditional labels/tooltips.To clone this PR locally use the Github CLI with command
gh pr checkout 2285You can tag me at @BuilderIO for anything you want me to fix or change