You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Changes
Adds an “edit page” link to the preview bar that links to the current
page record editor (when we have id + __typename), so editors can jump
from a preview page straight into the CMS record.
## Documentation link
See:
https://github.com/voorhoede/head-start/blob/feat/edit-page/docs/preview-mode.md#edit-in-datocms-link
# How to test
<img width="1434" height="434" alt="SCR-20260120-nsbz"
src="https://github.com/user-attachments/assets/8dc06968-6f97-4f93-8fea-c7804d2d8c3a"
/>
# Checklist
- [ ] I have performed a self-review of my own code
- [ ] I have made sure that my PR is easy to review (not too big,
includes comments)
- [ ] I have made updated relevant documentation files (in project
README, docs/, etc)
- [ ] I have added a decision log entry if the change affects the
architecture or changes a significant technology
- [ ] I have notified a reviewer
<!-- Please strike through and check off all items that do not apply
(rather than removing them) -->
Copy file name to clipboardExpand all lines: docs/preview-mode.md
+60-1Lines changed: 60 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,12 @@
6
6
7
7
To enable preview mode for a git branch, you must add it to [`config/preview.ts`](../config/preview.ts). Preview branches will deploy as `output: 'server'` rather than `output: 'hybrid'`, ignoring all `getStaticPaths()` and always rendering the page during run-time. The `preview` branch is configured as one of the preview branches and is automatically kept in sync with the `main` branch, so it can be used as preview equivalent, for example from the CMS.
8
8
9
+
> [!TIP]
10
+
> To enable preview mode during local development:
11
+
> - Make sure your current git branch is included in [`config/preview.ts`](../config/preview.ts).
12
+
> - Set `HEAD_START_PREVIEW_SECRET` and `DATOCMS_READONLY_API_TOKEN` in your local `.env`.
13
+
> - Enter preview mode via `/api/preview/enter/?secret=...` (or the preview login form).
14
+
9
15
To protect a part of the page that must only be available in preview mode, you can wrap it in the `PreviewModeProvider`, as is done in the [`Default.astro` layout](../src/layouts/Default.astro):
The `record` prop is used to generate the "edit in CMS" link in the preview bar.
76
+
65
77
## Preview mode bar
66
78
67
79
When in preview mode a bar in the user interface displays the status of the connection with the CMS, along with a link to exit preview mode. Depending on the layout of your project, you may want to move the preview mode bar to another position, for example if your project has a sticky header.
80
+
81
+
## Edit in CMS link
82
+
83
+
In preview mode, the preview bar shows an **"edit in CMS"** link that opens the record in DatoCMS.
84
+
85
+
### How it works
86
+
87
+
The link is automatically generated from the `record` prop passed to `PreviewModeSubscription`. The URL is built from:
88
+
-**Project name**: extracted from `internalDomain` in `@lib/site.json`
89
+
-**Environment**: from `datocms-environment.ts`
90
+
-**Record info**: `id` + `type` (from `record` prop) → resolved to `itemTypeId` via auto-generated mappings
91
+
92
+
If any part can't be resolved, the link doesn't render.
93
+
94
+
### Usage
95
+
96
+
Pass the `record` prop to `PreviewModeSubscription`:
97
+
98
+
```astro
99
+
<PreviewModeSubscription
100
+
query={query}
101
+
variables={variables}
102
+
record={{ type: page.__typename, id: page.id }}
103
+
/>
104
+
```
105
+
106
+
Your GraphQL query needs:
107
+
108
+
```graphql
109
+
queryMyPage {
110
+
page {
111
+
id
112
+
__typename
113
+
# ... other fields
114
+
}
115
+
}
116
+
```
117
+
118
+
### Auto-generated files
119
+
120
+
-`src/lib/datocms/itemTypes.json` — `__typename` → item type id (generated, in `.gitignore`)
0 commit comments