Skip to content

fix: show the loading placeholder while a doc's tree is fetched - #342

Open
iftakharul-islam wants to merge 1 commit into
developfrom
fix/doc-listing-loading-placeholder
Open

iftakharul-islam wants to merge 1 commit into
developfrom
fix/doc-listing-loading-placeholder

Conversation

@iftakharul-islam

Copy link
Copy Markdown
Member

Follow-up to #340 (already merged). Fixes a UX regression that came in with the lazy loading.

Tracking issue: weDevsOfficial/wedocs-pro#366

Symptom

Opening a documentation showed a blank screen first, then everything appeared at once with no transition — no skeleton, no animation.

Why

Three things, all introduced or exposed by the lazy loading in #340.

1. The placeholder was gated on the wrong flag. DocListing used the store's loading, which tracks the dashboard's request. During a doc's own child fetch that flag is false, so ! loading was true and the component rendered its "No section or article found" branch for the entire request.

2. The selectors were not subscribed. getSectionsDocs and getDocArticles were called with an empty dependency list:

}, [] );

so they kept returning the value captured on first render and only refreshed when something unrelated forced a re-render. That is what made content arrive late rather than as soon as the fetch resolved.

3. A doc with no sections would wait forever. loadDocTree only called markChildrenLoaded when sections.length was truthy — a guard I added in #340 to make failed requests retry. But that conflates "request failed" with "this doc genuinely has no sections", so an empty documentation never became childrenLoaded.

Changes

  • Derive this screen's readiness from its own state: docsLoading || loadingChildren || ! childrenLoaded
  • Give the section/article selectors real dependencies ([ id, docs ]) so they track the store
  • Mark a branch loaded whenever the request succeeds, empty or not, in a try/finally so loadingChildren always clears; a genuine failure stays unmarked and retries
  • Track the requested ID in the effect, so an unmarked branch after a failure cannot become a request loop

Verification

Loading gate checked across every transition:

State loading Renders
Mount, nothing started true Skeleton
Child fetch in flight true Skeleton
Loaded, has sections false Content
Loaded, no sections false Empty state (not a spinner)
Dashboard still loading true Skeleton
Revisit cached branch false Content immediately

Confirmed against the live API that the empty case returns HTTP 200 with 0 sections, so it now marks loaded and shows its empty state rather than waiting forever.

Build and no-undef lint clean.

Not yet visually confirmed in a browser — the Playwright profile was locked by a running Chrome instance while I was working, so the skeleton itself has not been seen on screen. The state logic is verified as above, but a quick manual check of the skeleton appearing on a slow doc would be worth doing before merge.

Opening a documentation rendered a blank screen until its sections
arrived, then filled in with no transition. The listing screen gated its
placeholder on the store's `loading` flag, which belongs to the
dashboard's own request and is false while a doc's branch is being
fetched, so the empty state rendered for the whole of that request.

Gate on this screen's own readiness instead: the dashboard request, the
child request, and whether the branch has been loaded at all.

The section and article selectors also subscribed with an empty
dependency list, so they kept returning the value captured on first
render and only updated when something else happened to re-render. That
is what made the content appear late rather than as soon as it arrived.

loadDocTree now marks a branch loaded whenever the request succeeds
rather than only when it returns sections, so a documentation with no
sections shows its empty state instead of waiting forever, and the
effect tracks the ID it requested so a failed fetch cannot become a
request loop.

Refs weDevsOfficial/wedocs-pro#366
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant