[WEB-2057]fix: fixed page title reset
Description
Fixed page title reset while navigation.
Type of Change
- [x] 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
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.
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
Possibly related PRs
- makeplane/plane#6491: Addresses improvements in page name display and title management, which directly aligns with the changes made in this PR.
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 f82d4a9eadb9d61ad0582f002e8e77b9e220308c and 3c2ceed2039fd0fa5162db911214f5eca9030f62.
π 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" directiveAdding the "use client" directive is necessary here since this component uses the
useHeadhook which manipulates browser-specific APIs likedocument.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 constantUsing the imported
SITE_TITLEconstant from@plane/constantsinstead of a hardcoded string is a better practice for maintainability. It ensures consistency across the application.
11-13: Fix for title reset issue looks goodThe 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_TITLEconstant. This should fix the title reset issue mentioned in the PR description.web/app/layout.tsx (4)
11-11: Good import for dynamic title handlingAdding the
PageHeadimport is necessary for the new dynamic title management approach.
17-29: Correctly removed static title from metadataRemoving the title from the metadata object is appropriate since it's now being managed dynamically through the
PageHeadcomponent. The other metadata properties are correctly maintained.
77-77: Good placement of PageHead componentThe
PageHeadcomponent is appropriately placed outside theAppProviderand early in the document body. This ensures the title is set correctly during navigation and prevents title resets.
76-78:β 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.jsconflicts with Next.js' static generation logic, as this file only renders during initial page load[1][10].- Solution: Use
next/headin 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.titleupdates can cause reverts when switching tabs[7]- Solution: Use
useEffectto 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
keyprops:<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:
- 1: https://nextjs.org/docs/messages/no-title-in-document-head
- 2: https://community.mixpanel.com/x/ask-ai/3qrxbbvxifww/nextjs-auto-page-view-event-showing-incorrect-meta
- 3: https://trackjs.com/blog/common-errors-in-nextjs-caching/
- 4: https://github.com/vercel/next.js/issues/28671
- 5: https://github.com/vercel/next.js/discussions/50872
- 6: https://vercel.com/blog/common-mistakes-with-the-next-js-app-router-and-how-to-fix-them
- 7: https://github.com/vercel/next.js/discussions/17717
- 8: https://nextjs.org/docs/pages/api-reference/components/head
- 9: https://nextjs.org/docs/architecture/fast-refresh
- 10: https://nextjs.org/docs/messages/no-document-title
- 11: https://focusreactive.com/typical-next-js-seo-pitfalls-to-avoid-in-2024/
- 12: https://github.com/vercel/next.js/issues/9992
- 13: https://nextjs.org/docs/pages/building-your-application/routing/custom-error
- 14: https://dev.to/mohith/a-deep-dive-into-nextjs-14-solving-common-intermediate-and-advanced-issues-hja
- 15: https://www.seancdavis.com/posts/resetting-state-on-nextjs-route-change/
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 leveragesnext/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.
πͺ§ 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
Pull Request Linked with Plane Work Items
- [WEB-2057] " Project name - Intake " is not displayed when user navigates to Intake under Tab header
Comment Automatically Generated by Plane