Skip to content

New quote save fails with "Quote not found" due to stale localStorage state #22

@darshgupta-wisdm

Description

@darshgupta-wisdm
                                                                                                                                                                                                                                      When creating a new quote via Quotes → New Quote → Builder, clicking Save throws the error:

Quote not found

Error originates from actions.ts:176.

  • Steps to Reproduce
    Open any existing quote in the builder (e.g., click Edit on a draft).
    Navigate away from the builder.
    Go to Quotes → New Quote → Builder.
    Select a client and add content.
    Click Save.

-Result:
The save fails with the error:

Quote not found
Expected Behavior

Creating a new quote from the New Quote Builder should always create a new quote record instead of attempting to update an existing one.

-Root Cause

The quote builder store uses Zustand's persist middleware, which stores the entire document (including id) in localStorage.

When navigating to:

/quotes/new/builder

the page initialization logic only resets the document when it is null:

if (!document) {
resetDocument()
}

However:

Zustand rehydrates the store from localStorage

The previous quote document (including its id) is restored

document is not null, so resetDocument() never runs

Later in handleSave():

document.id exists

createQuote() is skipped

updateQuote() is called instead

The stale ID does not match the intended new quote

Result: "Quote not found" error

Suggested Fix

Ensure the document store is always reset when opening the new quote builder.

File:

app/(dashboard)/quotes/new/builder/page.tsx

Update the initialization effect to reset the document unconditionally on mount, using a ref guard so it only runs once.

Example:

const hasInitialized = useRef(false)

useEffect(() => {
if (!hasInitialized.current) {
resetDocument()
hasInitialized.current = true
}
}, [])

This ensures that persisted documents from localStorage do not interfere with creating a new quote.

Related

PR #11 (fix/issue-3)

Fixed the handleSave() branching logic.

Did not account for Zustand persistence, which prevents resetDocument() from running.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions