Skip to content

⚡️ perf: try to fix layout flick #8480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

⚡️ perf: try to fix layout flick #8480

wants to merge 4 commits into from

Conversation

arvinxx
Copy link
Member

@arvinxx arvinxx commented Jul 17, 2025

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • 📝 docs
  • 🔨 chore

🔀 变更说明 | Description of Change

📝 补充信息 | Additional Information

Summary by Sourcery

Implement OIDC authentication support, introduce URL segment variant routing, refactor sidebar and server layouts to reduce flicker and unify link handling, and fix JWT public key import.

New Features:

  • Add OIDC authentication handling by processing the new Oidc-Auth header in middleware and tRPC context.
  • Support URL segment variants via a new segmentVariants property in the server config store and the InnerLink component.

Bug Fixes:

  • Fix JWT public key import by creating a clean JWK object with only public fields and renaming the function to getVerificationKey.

Enhancements:

  • Extract the ChatAction component and replace direct next/link usage in sidebar with InnerLink for consistent routing.
  • Introduce NewServerLayout for unified desktop/mobile rendering and refactor chat workspace layout to pass props asynchronously.
  • Define the LOBE_CHAT_OIDC_AUTH_HEADER constant for header consistency.

Copy link

vercel bot commented Jul 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lobe-chat-database ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2025 4:59pm
lobe-chat-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2025 4:59pm

Copy link
Contributor

sourcery-ai bot commented Jul 17, 2025

Reviewer's Guide

Refactors sidebar navigation and layout composition to improve performance and flicker by extracting ChatAction, introducing a dynamic InnerLink with segmentVariants, switching to an async NewServerLayout, enhancing JWKS public key handling, and integrating OIDC authentication.

Sequence diagram for OIDC authentication in checkAuth middleware

sequenceDiagram
    participant Client
    participant Middleware
    participant OIDCProvider
    Client->>Middleware: Send request with Oidc-Auth header
    Middleware->>OIDCProvider: validateOIDCJWT(oidcAuthorization)
    OIDCProvider-->>Middleware: OIDC payload (userId, ...)
    Middleware->>Middleware: Merge OIDC userId into jwtPayload
    Middleware->>Middleware: Skip checkAuthMethod if OIDC used
Loading

Class diagram for new and refactored navigation components

classDiagram
    class TopActions {
        +tab
        +isPinned
    }
    class ChatAction {
        +isPinned
        +tab
    }
    class InnerLink {
        +href
        +children
        +...props
    }
    TopActions --> ChatAction : uses
    TopActions --> InnerLink : uses
    ChatAction --> InnerLink : uses
Loading

Class diagram for new ServerLayout and related layout changes

classDiagram
    class ServerLayout {
        +Desktop
        +Mobile
        +children
    }
    class RouteVariants {
        +getIsMobile(props)
    }
    ServerLayout ..> RouteVariants : uses
Loading

Class diagram for server config store changes

classDiagram
    class ServerConfigState {
        +featureFlags: IFeatureFlags
        +isMobile?: boolean
        +segmentVariants?: string
        +serverConfig: GlobalServerConfig
    }
    class ServerConfigStoreProvider {
        +featureFlags?
        +isMobile?
        +segmentVariants?
        +serverConfig?
        +children
    }
    ServerConfigStoreProvider --> ServerConfigState : provides
Loading

Class diagram for OIDC JWT verification refactor

classDiagram
    class getVerificationKey {
        +async()
    }
    class validateOIDCJWT {
        +async(token: string)
    }
    validateOIDCJWT --> getVerificationKey : uses
Loading

File-Level Changes

Change Details Files
Extracted chat button logic into a standalone component and unified link rendering
  • Removed inline Link and switchBackToChat calls in TopActions
  • Created ChatAction component for chat tab with session-based URL
  • Replaced all Next.js Links in TopActions with InnerLink for consistent routing
src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx
src/app/[variants]/(main)/_layout/Desktop/SideBar/ChatAction.tsx
Introduced InnerLink for dynamic URL prefixing based on segmentVariants
  • Added InnerLink component that reads segmentVariants from server config store
  • Replaced direct Link usage to prefix all routes with active variant segment
src/components/InnerLink.tsx
Propagated segmentVariants through server config provider and store
  • Extended ServerConfigStoreProvider to accept segmentVariants prop
  • Added segmentVariants field to serverConfig store and initial state
  • Passed variants to GlobalProvider and root layouts
src/store/serverConfig/Provider.tsx
src/store/serverConfig/store.ts
src/layout/GlobalProvider/index.tsx
src/app/[variants]/layout.tsx
Replaced ServerLayout with async NewServerLayout component
  • Created NewServerLayout that selects Desktop or Mobile based on isMobile
  • Updated chat workspace layout to use NewServerLayout with props spread
src/components/server/NewServerLayout.tsx
src/app/[variants]/(main)/chat/(workspace)/layout.tsx
Improved JWKS public key extraction and renamed function
  • Renamed getJWKSPublicKey to getVerificationKey
  • Built a clean JWK object containing only public RSA fields
  • Filtered out undefined properties before calling importJWK
src/libs/oidc-provider/jwt.ts
Integrated OIDC authentication into middleware and context
  • Added LOBE_CHAT_OIDC_AUTH_HEADER constant for OIDC tokens
  • Extended auth middleware to detect and validate OIDC JWT and merge userId
  • Updated trpc lambda context to use the new header constant
src/app/(backend)/middleware/auth/index.ts
src/libs/trpc/lambda/context.ts
src/const/auth.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

codecov bot commented Jul 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.26%. Comparing base (785406b) to head (d04e7f3).
Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #8480       +/-   ##
===========================================
+ Coverage   85.31%   96.26%   +10.94%     
===========================================
  Files         907       17      -890     
  Lines       68464     2917    -65547     
  Branches     6268      515     -5753     
===========================================
- Hits        58413     2808    -55605     
+ Misses      10051      109     -9942     
Flag Coverage Δ
app ?
server 96.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lobehubbot
Copy link
Member

👍 @arvinxx

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

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.

2 participants