Skip to content

fix brief page not found while accessing plug page#16452

Open
khavinshankar wants to merge 2 commits into
developfrom
khavinshankar/fix/fix-brief-page-not-found-while-accessing-plug-page
Open

fix brief page not found while accessing plug page#16452
khavinshankar wants to merge 2 commits into
developfrom
khavinshankar/fix/fix-brief-page-not-found-while-accessing-plug-page

Conversation

@khavinshankar

@khavinshankar khavinshankar commented Jun 10, 2026

Copy link
Copy Markdown
Member

Proposed Changes

Currently when accessing plugin page, there is a brief page not found before the plugin page loads completely. Go to a plugin tab in encounter, do a hard refresh, the error can be noticed.

Fixes #issue_number

  • Added plugin loading context which would expose plugin loading state, which can be used by app router to show loading logo when accessing plugin pages instead of page not found

Tagging: @ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate the bug or test the new feature.
  • Update product documentation.
  • Ensure that UI text is placed in I18n files.
  • Prepare a screenshot or demo video for the changelog entry and attach it to the issue.
  • Request peer reviews.
  • Complete QA on mobile devices.
  • Complete QA on desktop devices.
  • Add or update Playwright tests for related changes

Summary by CodeRabbit

Release Notes

  • Improvements
    • Improved application startup experience with proper loading state management
    • Loading screen now displays while plugins are being initialized instead of showing error states

@khavinshankar khavinshankar requested review from a team and Copilot June 10, 2026 07:39
@netlify

netlify Bot commented Jun 10, 2026

Copy link
Copy Markdown

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit c5802a1
🔍 Latest deploy log https://app.netlify.com/projects/care-ohc/deploys/6a2fb385870fd30008be9cfd
😎 Deploy Preview https://deploy-preview-16452.preview.ohc.network
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR updates the plugin loading context to carry both apps and a combined loading state. PluginEngine computes the loading state from enabled-plugins and plugin manifest queries, stores it in the updated context shape, and AppRouter consumes this state to show a Loading screen during plugin initialization instead of an ErrorPage.

Changes

Plugin Loading State and UI

Layer / File(s) Summary
Loading context and hook definition
src/hooks/useCareApps.tsx
CareAppsContextValue type bundles apps with isLoading boolean. CareAppsContext is updated to this shape. useCareApps returns ctx.apps, and new useCareAppsLoading hook exposes ctx.isLoading with fallback to false.
Plugin loading state tracking and provision
src/PluginEngine.tsx
The enabled-plugins useQuery destructures isEnabledPluginsLoading. A combined arePluginsLoading is computed from enabled-plugins loading and plugin manifest query loading states. CareAppsContext.Provider value is updated to pass { apps: pluginsQuery, isLoading: arePluginsLoading } to children.
Router loading fallback UI
src/Routers/AppRouter.tsx
AppRouter imports Loading component and useCareAppsLoading hook. When routes are unavailable, arePluginsLoading determines whether to display Loading or ErrorPage: shows Loading during plugin initialization, otherwise falls back to error page.

Suggested reviewers

  • gigincg
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly addresses the main issue being fixed - a brief 'page not found' error appearing when accessing plugin pages. It is specific and directly related to the primary change in the changeset.
Description check ✅ Passed The description includes the proposed changes section with issue reference placeholder and bullet points explaining the fix. However, all merge checklist items are unchecked, indicating no testing, documentation, or QA work has been completed yet.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch khavinshankar/fix/fix-brief-page-not-found-while-accessing-plug-page

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

⚠️ Merge Checklist Incomplete

Thank you for your contribution! To help us review your PR efficiently, please complete the merge checklist in your PR description.

Your PR will be reviewed once you have marked the appropriate checklist items.

To update the checklist:

  • Change - [ ] to - [x] for completed items
  • Only check items that are relevant to your PR
  • Leave items unchecked if they don't apply

The checklist helps ensure code quality, testing coverage, and documentation are properly addressed.

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a brief "page not found" flash that appeared during hard-refreshes on plugin pages by exposing a plugin-loading state through context and using it in the router to show a loading spinner instead of the error page while plugins are still registering their routes.

  • useCareApps.tsx: Wraps the context value in a CareAppsContextValue object ({ apps, isLoading }) and adds a new useCareAppsLoading() hook that safely returns false outside the provider.
  • PluginEngine.tsx: Derives arePluginsLoading from both the enabled-plugins query and individual plugin manifest queries, then passes it into context.
  • AppRouter.tsx: Falls back to <Loading /> instead of <ErrorPage /> while arePluginsLoading is true, eliminating the flash.

Confidence Score: 5/5

Safe to merge — the change is a targeted, low-risk fix that adds a loading guard with no impact on existing routes or authenticated flows.

The context shape change is backward-compatible (all consumers of useCareApps still receive the same array via ctx.apps), the new useCareAppsLoading hook is nil-safe, and the loading gate in AppRouter only fires on the fallback branch that previously always showed an error page. The logic for deriving arePluginsLoading correctly covers both the enabled-plugins fetch and individual manifest fetches, and will resolve to false even when a manifest fetch fails (since a failed query is no longer isLoading).

No files require special attention.

Important Files Changed

Filename Overview
src/hooks/useCareApps.tsx Refactors CareAppsContext from a plain array to an object with apps and isLoading fields; adds useCareAppsLoading hook that safely returns false outside the provider.
src/PluginEngine.tsx Extracts isEnabledPluginsLoading from useQuery and derives arePluginsLoading combining it with individual plugin query states; passes the composite loading flag into context.
src/Routers/AppRouter.tsx Uses useCareAppsLoading() to show a <Loading /> spinner instead of <ErrorPage /> while plugins are still registering their routes.

Reviews (2): Last reviewed commit: "track plugs loading state in the same co..." | Re-trigger Greptile

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses an incorrect “page not found” experience when directly accessing plugin-provided pages before plugin routes have finished loading. It introduces a shared “plugins loading” state from the plugin engine and uses it in the main router to show a loader instead of a 404 during initial plugin resolution.

Changes:

  • Expose plugin loading state via a new CareAppsLoadingContext in useCareApps.
  • Provide that loading state from PluginEngine based on enabled-plugin and manifest query load status.
  • Update AppRouter fallback behavior to render <Loading /> (instead of <ErrorPage />) while plugins are still loading.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Routers/AppRouter.tsx Uses the new loading signal to avoid premature 404s while plugin routes are still being registered.
src/PluginEngine.tsx Computes and provides a consolidated “plugins loading” boolean via context.
src/hooks/useCareApps.tsx Adds the loading context + hook to allow consumers (like the router) to read plugin load state.

Comment thread src/hooks/useCareApps.tsx Outdated
Comment on lines 18 to 20
export const CareAppsLoadingContext = createContext<boolean>(false);

export const useCareApps = () => {
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 10, 2026

Copy link
Copy Markdown

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: c5802a1
Status: ✅  Deploy successful!
Preview URL: https://40fb6d29.care-preview-a7w.pages.dev
Branch Preview URL: https://eng-555-handle-brief-page-no.care-preview-a7w.pages.dev

View logs

@yash-learner yash-learner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

🎭 Playwright Test Results

Status: ❌ Failed
Test Shards: 3

Metric Count
Total Tests 321
✅ Passed 319
❌ Failed 2
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #9533

@rithviknishad rithviknishad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, why have a new context when we can use the same context?

@rithviknishad

Copy link
Copy Markdown
Member

also: link jira ticket

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/hooks/useCareApps.tsx`:
- Around line 16-19: The CareAppsContextValue type definition currently uses the
type keyword for defining an object shape, but the coding guidelines prefer
using interface for object type definitions. Convert the type
CareAppsContextValue declaration from a type alias to an interface, changing
from type keyword to interface keyword and adjusting the syntax accordingly
(replacing the equals sign with the interface body syntax).

In `@src/PluginEngine.tsx`:
- Around line 169-171: The CareAppsContext.Provider value prop contains an
inline object that creates a new reference on every render, causing unnecessary
re-renders in context consumers. Wrap the context value object with the useMemo
hook (already imported on line 13) and specify pluginsQuery and
arePluginsLoading as dependencies, so the object reference only changes when
these dependencies actually change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e473de16-d38f-4e26-940d-72bf45e03a38

📥 Commits

Reviewing files that changed from the base of the PR and between 8234cd5 and c5802a1.

📒 Files selected for processing (2)
  • src/PluginEngine.tsx
  • src/hooks/useCareApps.tsx

Comment thread src/hooks/useCareApps.tsx
Comment on lines +16 to +19
export type CareAppsContextValue = {
apps: CareAppsContextType;
isLoading: boolean;
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Use interface instead of type for object type definitions.

Per coding guidelines, prefer interface for defining object shapes in TypeScript.

Suggested fix
-export type CareAppsContextValue = {
-  apps: CareAppsContextType;
-  isLoading: boolean;
-};
+export interface CareAppsContextValue {
+  apps: CareAppsContextType;
+  isLoading: boolean;
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export type CareAppsContextValue = {
apps: CareAppsContextType;
isLoading: boolean;
};
export interface CareAppsContextValue {
apps: CareAppsContextType;
isLoading: boolean;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useCareApps.tsx` around lines 16 - 19, The CareAppsContextValue
type definition currently uses the type keyword for defining an object shape,
but the coding guidelines prefer using interface for object type definitions.
Convert the type CareAppsContextValue declaration from a type alias to an
interface, changing from type keyword to interface keyword and adjusting the
syntax accordingly (replacing the equals sign with the interface body syntax).

Source: Coding guidelines

Comment thread src/PluginEngine.tsx
Comment on lines +169 to +171
<CareAppsContext.Provider
value={{ apps: pluginsQuery, isLoading: arePluginsLoading }}
>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Memoize the context value to prevent unnecessary re-renders.

The inline object { apps: pluginsQuery, isLoading: arePluginsLoading } creates a new reference on every render, which can trigger re-renders in all context consumers even when the actual data hasn't changed.

Suggested fix
+  const contextValue = useMemo(
+    () => ({ apps: pluginsQuery, isLoading: arePluginsLoading }),
+    [pluginsQuery, arePluginsLoading],
+  );
+
   return (
     <Suspense fallback={<Loading />}>
       <ErrorBoundary
         fallback={
           <div className="flex h-screen w-screen items-center justify-center">
             Care has encountered an unexpected error.
           </div>
         }
       >
-        <CareAppsContext.Provider
-          value={{ apps: pluginsQuery, isLoading: arePluginsLoading }}
-        >
+        <CareAppsContext.Provider value={contextValue}>
           <Suspense fallback={<Loading />}>{children}</Suspense>
         </CareAppsContext.Provider>
       </ErrorBoundary>
     </Suspense>
   );

Note: useMemo is already imported on line 13.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/PluginEngine.tsx` around lines 169 - 171, The CareAppsContext.Provider
value prop contains an inline object that creates a new reference on every
render, causing unnecessary re-renders in context consumers. Wrap the context
value object with the useMemo hook (already imported on line 13) and specify
pluginsQuery and arePluginsLoading as dependencies, so the object reference only
changes when these dependencies actually change.

@Jacobjeevan

Copy link
Copy Markdown
Contributor

@khavinshankar Do add the relevant jira ticket (also for future: add as prefix for branch name).

@nihal467 nihal467 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADD THE JIRA TICKET TO THE PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants