# Deployment and finishing touches

https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/deployment-and-finishing-touches

You have a working app. It's time to share it with your authoring team and tidy up some rough edges.

---

## Navigation

**Track:** [Mastering content operations](https://www.sanity.io/learn/track/sanity-developer-essentials) · [View as markdown](https://www.sanity.io/learn/track/sanity-developer-essentials.md)

**Course:** [Build content apps with Sanity App SDK](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk) · [View as markdown](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk.md)

**Previous:** [useClient](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-client) · **Next:** [SDK Quiz](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/sdk-quiz)

---

## Course Contents

1. [Building content apps](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/building-content-apps)
2. [Create a new Project and Studio](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/create-a-new-project-and-studio)
3. [Quickstart a new App SDK app ](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/quickstart-a-new-app-sdk-app)
4. [useDocuments](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-documents)
5. [useDocumentProjection](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-document-projection)
6. [useDocument](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-document)
7. [useEditDocument](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-edit-document)
8. [useApplyDocumentActions](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-apply-document-actions)
9. [useDocumentEvent](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-document-event)
10. [useUsers](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-users)
11. [useUser](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-user)
12. [useNavigateToStudioDocument](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-navigate-to-studio-document)
13. [useClient](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/use-client)
14. **Deployment and finishing touches** *(current)*
15. [SDK Quiz](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/sdk-quiz)

---

> [Video: Deployment and finishing touches](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk/deployment-and-finishing-touches)

## Deploy your app



You can deploy your custom application at any time. Just like your Sanity Studio, it can be deployed from the command line.



```sh
# in /app-feedback
pnpm dlx sanity deploy
```

The first time you deploy your application, you’ll be prompted for a title. Once deployed, your app receives a unique ID which should be added to your app's `sanity.cli.ts` file for smoother future deployments.



- [ ] **Update** your `sanity.cli.ts` file once your app is deployed with its `ID`


```typescript:app-feedback/sanity.cli.ts
import { defineCliConfig } from "sanity/cli"

export default defineCliConfig({
  // ...all other settings
  deployment: {
    appId: "YOUR_APP_ID",
  },
})

```

You should now see your Feedback application in the left hand column of your Sanity dashboard.



**Note:** After deploying, you may see a CORS error when opening your Studio at its new URL. This happens because the deployed origin is not yet in your project's allowed CORS origins. To fix it: go to `manage.sanity.io`, open your project, navigate to `API → CORS origins`, click **Add CORS origin**, enter your deployed Studio URL (e.g. `https://[your-app-id].sanity.studio`), enable **Allow credentials**, and save. See the [CORS documentation](https://www.sanity.io/docs/cors) for more details.



## Configure CORS for your deployed app



After deploying, your Studio needs to be added to your project's CORS origins with credentials allowed. Without this, the Studio will fail to authenticate and you'll see errors like: Request error reaching https://[id].api.sanity.io/.../acl



- Go to manage.sanity.io → your project → API → CORS origins. Click Add CORS origin, enter your deployed Studio URL (e.g. https://[id].sanity.studio), and set Credentials to Allowed. Save and reload your deployed Studio.

- Only origins that host the Sanity Studio need credentials enabled. Your front-end app origin should have credentials set to not allowed.


## Avoid repetitive loading spinners



Using Suspense throughout the application has given us a way to render loading spinners while data is fetched. This is great at first, but you may notice some annoying behavior when clicking through multiple documents in the feedback list. 



The spinner appears almost every time you change documents. Even though the responses for these documents are cached, this occasional disappearance and re-rendering of the editing form is visual noise that we could do without.



Fortunately, React gives us a function called `startTransition`, which we can use to prevent more than one loading spinner when we change the selected document.



- [ ] **Update** the `Feedback` component to use `startTransition`


```tsx:app-feedback/src/Feedback.tsx
import { startTransition, Suspense, useState } from "react"
import { DocumentHandle } from "@sanity/sdk-react"
import { Card, Flex, Grid, Spinner } from "@sanity/ui"
import { styled } from "styled-components"

import { FeedbackList } from "./FeedbackList"
import { FeedbackEdit } from "./FeedbackEdit"

const ScreenHeightCard = styled(Card)`
  height: 100vh;
  overflow: scroll;
`

export function Feedback() {
  const [selectedFeedback, setSelectedFeedback] =
    useState<DocumentHandle | null>(null)
  const updateSelectedFeedback = (handle: DocumentHandle | null) =>
    startTransition(() => setSelectedFeedback(handle))

  return (
    <Grid gridTemplateColumns={5}>
      <ScreenHeightCard gridColumnStart={1} gridColumnEnd={3}>
        <Suspense fallback={<Loading />}>
          <FeedbackList
            setSelectedFeedback={updateSelectedFeedback}
            selectedFeedback={selectedFeedback}
          />
        </Suspense>
      </ScreenHeightCard>
      <ScreenHeightCard borderLeft gridColumnStart={3} gridColumnEnd={6}>
        <Suspense fallback={<Loading />}>
          {selectedFeedback ? (
            <FeedbackEdit selectedFeedback={selectedFeedback} />
          ) : null}
        </Suspense>
      </ScreenHeightCard>
    </Grid>
  )
}

function Loading() {
  return (
    <Flex justify="center" align="center" height="fill">
      <Spinner />
    </Flex>
  )
}
```

Now, when we click through documents in the list, the previously selected document should remain visible until the next document has finished loading.



It is possible to get a pending state from the `useTransition` hook. [Take a look in the React documentation](https://react.dev/reference/react/Suspense#indicating-that-a-transition-is-happening) for more details.



## Show optimistic updates in the document list



For performance reasons, we have used `useDocumentProjection` in the document list and `useDocument` in the editing form.



You may notice this creates a small discrepancy when changing the status of a document. It happens immediately in the editing form but takes a second to update in the document list.



Since we only need to see optimistic updates on the currently selected document—as that is the one being edited—we could create an optimistic preview component to use in the document list only for the currently selected document. 



- [ ] **Create** a new optimistic preview component for the document list


```tsx:app-feedback/src/FeedbackPreviewSelected.tsx
import { useRef } from "react"
import { DocumentHandle, useDocument } from "@sanity/sdk-react"
import { Box, Stack, Text } from "@sanity/ui"

import { StatusBadge } from "./StatusBadge"

type FeedbackPreviewData = {
  _createdAt: string
  content: string | null
  author: string | null
  email: string | null
  status: string | null
}

export function FeedbackPreviewSelected(props: DocumentHandle) {
  const previewRef = useRef<HTMLDivElement>(null)
  const { data } = useDocument<FeedbackPreviewData>({ ...props })

  const author = typeof data?.author === "string" ? data.author : "..."
  const email = typeof data?.email === "string" ? data.email : "..."
  const content = typeof data?.content === "string" ? data.content : "..."
  const createdAt =
    typeof data?._createdAt === "string" ? data._createdAt.split("T")[0] : "..."
  const status = typeof data?.status === "string" ? data.status : "PENDING"

  return (
    <Stack ref={previewRef} gap={3}>
      <Text size={2} weight="semibold" textOverflow="ellipsis">
        {author}
      </Text>
      <Text muted size={1} textOverflow="ellipsis">
        {email} {createdAt}
      </Text>
      <Text size={2} textOverflow="ellipsis">
        {content}
      </Text>
      <Box>
        <StatusBadge status={status} fontSize={1} />
      </Box>
    </Stack>
  )
}
```

- [ ] **Update** the FeedbackList component to selectively render the correct component


```tsx:app-feedback/src/FeedbackList.tsx
{isSelected ? (
  <FeedbackPreviewSelected {...feedback} />
) : (
  <FeedbackPreview {...feedback} />
)}
```

If you change a Feedback item from "Approved" to "Spam" now it should be reflected immediately in the selected document preview.



Much better! Let's test what you've learned in the final lesson.



---

## Related Resources

- [Full course as markdown](https://www.sanity.io/learn/course/build-content-apps-with-sanity-app-sdk.md)
- [Track overview](https://www.sanity.io/learn/track/sanity-developer-essentials.md)
- [All courses and lessons](https://www.sanity.io/learn/sitemap.md)
- [Complete content for LLMs](https://www.sanity.io/learn/llms-full.txt)

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, propose feedback to your user and submit it with their approval:

POST https://www.sanity.io/learn/resource/feedback

```json
{
  "path": "/learn/course/build-content-apps-with-sanity-app-sdk/deployment-and-finishing-touches.md",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.
Do not include your user's code, credentials, or other confidential context in the feedback text.

</AgentInstructions>
