Skip to content

[WEB-2057]fix: fixed page title reset #6779

Closed
vamsikrishnamathala wants to merge 1 commit intopreviewfrom
fix-page_title
Closed

[WEB-2057]fix: fixed page title reset #6779
vamsikrishnamathala wants to merge 1 commit intopreviewfrom
fix-page_title

Conversation

@vamsikrishnamathala
Copy link
Member

@vamsikrishnamathala vamsikrishnamathala commented Mar 19, 2025

Description

Fixed page title reset while navigation.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

References

WEB-2057

Summary by CodeRabbit

  • New Features

    • Improved dynamic page title behavior: custom titles are now prioritized, while a centralized default is applied when absent.
    • Upgraded layout integration with a dedicated header for managing metadata to enhance page consistency.
  • Chores

    • Optimized title management components for client-side rendering to ensure smoother performance.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

Walkthrough

This pull request updates how the document title is managed in the application. The use-page-title.tsx hook now assigns the title using a centralized constant (SITE_TITLE) when no title is provided. In addition, the layout in layout.tsx has been modified to remove the static title from the metadata and to include the <PageHead /> component for handling the title dynamically. A "use client"; directive has also been added to the page-title.tsx file to ensure it is treated as a client component.

Changes

File/Path Change Summary
packages/ui/src/hooks/use-page-title.tsx and web/app/layout.tsx Updated title management: In hooks, the fallback title is now set using the imported SITE_TITLE; in layout, the title in metadata is removed and <PageHead /> is added.
web/core/components/core/page-title.tsx Added the "use client"; directive at the beginning of the file to designate it as a client component.

Sequence Diagram(s)

sequenceDiagram
    participant RL as RootLayout
    participant PH as PageHead
    participant UPT as usePageTitle Hook
    participant DOC as Document

    RL->>PH: Render PageHead component
    PH->>UPT: Invoke usePageTitle with (optional) title
    alt Title provided
        UPT-->>DOC: Set document.title to provided title
    else No title provided
        UPT-->>DOC: Set document.title to SITE_TITLE
    end
Loading

Possibly related PRs

Suggested reviewers

  • sriramveeraghanta
  • anmolsinghbhatia

Poem

I'm a rabbit coding in the digital glen,
Hopping through titles with a clever yen.
From constants to layouts, every line does gleam,
With a twitch of whiskers and a code-stream dream.
May our changes bound with joy, in ASCII and beam! 🐇💻

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f82d4a9 and 3c2ceed.

📒 Files selected for processing (3)
  • packages/ui/src/hooks/use-page-title.tsx (2 hunks)
  • web/app/layout.tsx (2 hunks)
  • web/core/components/core/page-title.tsx (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
web/app/layout.tsx (1)
web/core/components/core/page-title.tsx (1) (1)
  • PageHead (10-16)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (7)
web/core/components/core/page-title.tsx (1)

1-1: Good addition of the "use client" directive

Adding the "use client" directive is necessary here since this component uses the useHead hook which manipulates browser-specific APIs like document.title. This ensures the component runs on the client side rather than during server rendering.

packages/ui/src/hooks/use-page-title.tsx (2)

2-2: Good use of centralized constant

Using the imported SITE_TITLE constant from @plane/constants instead of a hardcoded string is a better practice for maintainability. It ensures consistency across the application.


11-13: Fix for title reset issue looks good

The updated implementation properly handles both cases - when a title is provided, it sets the document title to that value, and when no title is provided, it falls back to the SITE_TITLE constant. This should fix the title reset issue mentioned in the PR description.

web/app/layout.tsx (4)

11-11: Good import for dynamic title handling

Adding the PageHead import is necessary for the new dynamic title management approach.


17-29: Correctly removed static title from metadata

Removing the title from the metadata object is appropriate since it's now being managed dynamically through the PageHead component. The other metadata properties are correctly maintained.


77-77: Good placement of PageHead component

The PageHead component is appropriately placed outside the AppProvider and early in the document body. This ensures the title is set correctly during navigation and prevents title resets.


76-78:

Details

❓ Verification inconclusive

Verify title persistence during navigation

The implementation looks correct, but it would be good to verify that the title now persists correctly during navigation between different pages in the application.


🌐 Web query:

What are common causes of page title reset in Next.js applications?

💡 Result:

Next.js applications can experience page title resets due to several architectural and implementation factors. Here are the most common causes and their solutions:

1. Incorrect Head Component Usage

  • Using _document.js for page titles: Defining <title> in _document.js conflicts with Next.js' static generation logic, as this file only renders during initial page load[1][10].
  • Solution: Use next/head in individual pages:
    import Head from 'next/head'
    
    export default function Page() {
      return (
        <Head>
          <title>Page-specific Title</title>
        </Head>
      )
    }

2. Client-Side Navigation Conflicts

  • Dynamic route caching: When using the same component for multiple dynamic routes, Next.js might retain previous state including head elements[12][15]
  • Tab switching issues: Browser behavior with document.title updates can cause reverts when switching tabs[7]
  • Solution: Use useEffect to force title updates on route changes:
    import { useRouter } from 'next/router'
    
    function Page() {
      const router = useRouter()
      useEffect(() => {
        document.title = "Current Page Title"
      }, [router.pathname])
    }

3. Caching and Revalidation Issues

  • Stale static generation: ISG/SSG pages might show outdated titles until revalidation[3][6]
  • Solution: Implement proper cache revalidation strategies:
    export async function getStaticProps() {
      return {
        props: {},
        revalidate: 60 // Refresh every 60 seconds
      }
    }

4. Client Component Limitations

  • "use client" components: Direct <title> manipulation in client components can conflict with Next.js' Head management[5]
  • Solution: Use context-based title management:
    // In layout component
    <HeadTitleProvider>
      <HeadTitle />
    </HeadTitleProvider>
    
    // In client components
    const { setTitle } = useHeadTitle()
    useEffect(() => {
      setTitle("Dynamic Title")
    }, [])

5. Multiple Head Instances

  • Component unmounting: Next.js clears <Head> contents when components unmount[8]
  • Duplicate elements: Multiple components modifying <title> without proper keys
  • Solution: Use unique key props:
    <Head>
      <title key="unique">My Title</title>
    </Head>

These issues primarily stem from Next.js' hybrid rendering model and head management optimizations. Proper understanding of static vs client-side rendering boundaries, along with strategic use of revalidation and state management, typically resolves title reset problems.

Citations:


Verify Title Persistence Across Navigations

The current implementation appears to wire up the necessary components, including the <PageHead /> which likely manages the document title. However, please manually verify that the page title remains consistent when navigating between different pages. Specifically, ensure:

  • The <PageHead /> component correctly leverages next/head (or an equivalent mechanism) to set the title.
  • There are no unexpected resets or conflicts during client-side routing, especially in scenarios involving dynamic routes or potential caching issues.
  • Manual testing confirms the title persists on route changes without being overwritten by defaults.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sriramveeraghanta sriramveeraghanta marked this pull request as draft March 20, 2025 08:30
@henit-chobisa henit-chobisa changed the title [WEB-2057]fix: fixed page title reset [WEB-2057]fix: fixed page title reset Mar 20, 2025
@makeplane makeplane deleted a comment from makeplane bot Mar 20, 2025
@makeplane makeplane deleted a comment from makeplane bot Mar 20, 2025
@makeplane makeplane deleted a comment from makeplane bot Mar 20, 2025
@makeplane makeplane deleted a comment from makeplane bot Mar 20, 2025
@henit-chobisa henit-chobisa changed the title [WEB-2057]fix: fixed page title reset [WEB-2057]fix: fixed page title reset Mar 20, 2025
@henit-chobisa henit-chobisa changed the title [WEB-2057]fix: fixed page title reset [WEB-2057]fix: fixed page title reset Mar 21, 2025
@makeplane makeplane deleted a comment from makeplane bot Mar 24, 2025
@henit-chobisa henit-chobisa changed the title [WEB-2057]fix: fixed page title reset [WEB-2057]fix: fixed page title reset Mar 24, 2025
@makeplane
Copy link

makeplane bot commented Mar 24, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

@henit-chobisa henit-chobisa changed the title [WEB-2057]fix: fixed page title reset [WEB-2057]fix: fixed page title reset Mar 24, 2025
@pushya22 pushya22 closed this Apr 7, 2025
@sriramveeraghanta sriramveeraghanta deleted the fix-page_title branch July 18, 2025 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛bug Something isn't working 🌐frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants