Skip to content

fix: preserve database name on create#322

Merged
appflowy merged 1 commit intomainfrom
fix/database-title-corruption
May 5, 2026
Merged

fix: preserve database name on create#322
appflowy merged 1 commit intomainfrom
fix/database-title-corruption

Conversation

@appflowy
Copy link
Copy Markdown
Contributor

@appflowy appflowy commented May 5, 2026

Summary

  • New databases were being silently renamed to "Grid" after creation. After a page refresh the corrupted name was shown, while the desktop app correctly keeps the user-provided container name.
  • Root cause: TitleEditable auto-focuses on mount with the child grid view's name ("Grid") because the container's name resolves a tick later. The remote-update effect bailed out while focused, and the subsequent blur unconditionally persisted the stale text via the API.
  • Fix: in TitleEditable, allow remote prop updates to sync into the contentEditable while focused as long as the user hasn't typed, and skip the blur write when no user edit occurred. In DatabaseView, add a breadcrumb-based fallback for resolving the container so the title reflects the container's name even when the shallow outline (depth=2) doesn't yet include it.

Test plan

  • Existing DatabaseView.databaseContainer tests pass
  • New unit test: breadcrumb fallback resolves the container when outline lookup fails
  • Manually create a new Grid database via the sidebar + menu → title shows "New Database"
  • Reload the page → title still shows "New Database"; database container name in the API is unchanged
  • Click outside the title without typing → no spurious rename request; container name stays "New Database"

🤖 Generated with Claude Code

Summary by Sourcery

Preserve database container titles when creating or loading databases by improving title synchronization and container resolution.

Bug Fixes:

  • Ensure remote title prop updates can sync into the focused TitleEditable when the user has not typed, preventing stale initial titles from overwriting correct names on blur.
  • Avoid sending a title update on blur when the user never edited the field, so auto-focused titles do not overwrite stored database names with default text.
  • Resolve the database container via breadcrumbs when it is missing from the shallow outline, ensuring the page title matches the container name after refresh.

Tests:

  • Extend DatabaseView database container tests to cover the breadcrumb-based container fallback resolution.

When a new database is created, the title input auto-focuses with the
child grid view's name ("Grid") because the container's name resolves a
tick later. The remote-update effect skipped re-syncing while focused, so
a subsequent blur (without any typing) silently persisted "Grid" via the
API — corrupting the container name. After refresh, the corrupted name
was loaded.

- TitleEditable: allow remote prop updates to flow into the contentEditable
  while focused as long as the user hasn't typed; skip the blur write when
  no user edit occurred.
- DatabaseView: fall back to the breadcrumb chain to resolve the database
  container when the shallow outline doesn't yet include it, so the title
  reflects the container's name immediately after refresh.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 5, 2026

Reviewer's Guide

Fixes incorrect database renaming by making TitleEditable safely accept remote name updates while focused (when the user hasn’t typed) and avoiding blur-based writes when no edits occurred, and by having DatabaseView fall back to breadcrumb ancestry to resolve the database container when it’s missing from the shallow outline, with added test coverage for the new breadcrumb behavior.

Sequence diagram for TitleEditable handling remote name updates while focused

sequenceDiagram
  actor User
  participant TitleEditable
  participant API

  User->>TitleEditable: NavigateToNewDatabase
  TitleEditable->>TitleEditable: MountAndAutoFocus
  TitleEditable->>API: RequestDatabaseMeta
  API-->>TitleEditable: RemoteNameUpdate NewDatabase
  TitleEditable->>TitleEditable: useEffectRemoteUpdate
  TitleEditable->>TitleEditable: CheckTypingWindow
  TitleEditable->>TitleEditable: CheckRecentUpdateWindow
  TitleEditable->>TitleEditable: DetectNoUserTyping
  TitleEditable->>TitleEditable: UpdateContentEditableWithRemoteName

  User->>TitleEditable: ClickOutsideWithoutTyping
  TitleEditable->>TitleEditable: handleBlur
  TitleEditable->>TitleEditable: DetectNoUserTyping
  TitleEditable--xAPI: SkipSendUpdateImmediately
Loading

Class diagram for TitleEditable name syncing and DatabaseView container resolution

classDiagram
  class TitleEditable {
    +boolean isFocused
    +Ref contentRef
    +Ref lastInputTimeRef
    +Ref lastUpdateSentTimeRef
    +Ref sentValuesRef
    +Ref blurTimerRef
    +Ref cleanupTimerRef
    +handleBlur()
    +useEffectRemoteUpdate()
  }

  class DatabaseView {
    +string databasePageId
    +Breadcrumb[] breadcrumbs
    +View view
    +View containerView
    +View breadcrumbContainerView
    +View pageView
    +computeView()
    +computeContainerView()
    +computeBreadcrumbContainerView()
  }

  class Breadcrumb {
    +string view_id
  }

  class View {
    +string id
    +string name
  }

  TitleEditable --> View : updatesTitleFor
  DatabaseView --> Breadcrumb : uses
  DatabaseView --> View : resolvesContainer
Loading

File-Level Changes

Change Details Files
Adjust TitleEditable’s remote update and blur behavior to avoid persisting stale titles when auto-focused.
  • Remove helper callbacks that wrapped last input/update timing and echo checks in favor of inline calculations using timestamps and the sent-values cache.
  • Change the remote name sync effect to early-return when the user is actively typing or a recent local update was sent, and when the incoming name matches a recently sent value.
  • Allow focused fields that have never received user input to accept remote name changes, updating the contentEditable text and restoring the cursor position when focused.
  • Update the blur handler to only send an update if the user has actually typed since focus, and to reset typing state after a short delay.
src/components/view-meta/TitleEditable.tsx
Resolve the database container via breadcrumbs when it can’t be found in the outline, and wire this into DatabaseView’s page meta selection.
  • Introduce retrieval of breadcrumbs via useBreadcrumb in DatabaseView.
  • Add a memoized breadcrumbContainerView that walks the breadcrumb chain to find the parent of the current view and checks whether it is a database container, skipping embedded views and cases where the containerView is already resolved.
  • Update the pageView selection logic to prefer outline-derived containerView, then breadcrumb-based container, then the direct view as a fallback.
src/components/app/DatabaseView.tsx
Extend DatabaseView tests to cover breadcrumb-based container resolution.
  • Augment the global __databaseViewTestState test shim to include breadcrumbs and mock useBreadcrumb to read from it.
  • Add a new test case that simulates an empty outline and a breadcrumb chain containing a container parent and grid child, then asserts that DatabaseView passes the container’s name and ID to the database and view-meta props.
src/pages/__tests__/DatabaseView.databaseContainer.test.tsx

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
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@appflowy appflowy merged commit 839188e into main May 5, 2026
13 checks passed
@appflowy appflowy deleted the fix/database-title-corruption branch May 5, 2026 16:53
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