editorial workflow's "view preview" fails in monorepo
- Dominant language
- JavaScript
- Stars
- 19.4k
- Forks
- 3.1k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
**Describe the bug**
Clicking on **View Preview** opens a page that says "Deploy canceled".
Netlify can be [configured](https://docs.netlify.com/configure-builds/common-configurations/#monorepos) to create several sites from different folders of the same github repository. Whenever something is committed to the repo, a build is triggered for each site. If there is no change in one site's folder, the build is canceled.
NetlifyCMS can be used in each of these folders. When the editorial workflow is enabled, saving a change creates a commit on a new branch in the repo. NetlifyCMS then displays a link called **Check for Preview** link. Clicking on that link asks netlify about the state of the builds triggered by the commit by sending a request like this:
https://website-name.netlify.app/.netlify/git/github/commits/commit-hash/status
The commit triggers a build for each website of the monorepo. When the builds are done, the above request returns a json like this:
```
{ "state": "success",
"statuses": [
{ ...
"description": "Deploy preview canceled.",
"target_url": [wrong link]
},
{ ...
"state": "success",
"description": "Deploy preview ready!",
"target_url": [correct link],
}
],
...
```
NetlifyCMS then displays a link **View Preview** that points to the target_url of the canceled build, which happens to be on the site that was not modified, instead of the target_url of the modified site which points to a working preview.
**To Reproduce**
Create a monorepo on github
I'm using the [starter kit for eleventy](https://github.com/surjithctly/neat-starter/tree/04744e5f4930c092df5c1b1b4c5923bd83cae7c7) that's mentioned in the NetlifyCMS documentation
You can create the first site from the **deploy to netlify** button in the readme, but the second site needs to be created with the "new site from git" button on your netlify team's page. (If you create the second one from the button, you can actually change its deploy settings to point to the first repository, but for some reason netlify will continue sending the commits to the second repo. This is probably good enough to reproduce this bug on the cms of the first site. )
Copy the files at the root into a subfolder for example site1 , and copy site1 to another subfolder site2.
Edit both NetlifyCMS configurations src/admin/config.yml (see my config.yml further down):
- add subfolder in front of the paths
- enable editorial workflow
Make sure you configure both sites correctly on netlify:
- Site settings > Build settings > Base directory
- Identity > Enable Identity
- Site settings > Identity > Services > Git Gateway > Enable Git Gateway
Once you have both sites running. Log into the admin of one of them, add a blog post, save. Click **Check for Preview** until it becomes **View Preview**, which takes you to the wrong place.
**Expected behavior**
**View Preview** should link to the correct preview.
**Applicable Versions:**
- Netlify CMS version 2.0.0
- Git provider: GitHub
- OS: Windows 10
- Browser version: Firefox
**CMS configuration**
This is the configuration for one of the folders, that happens to be called hestia-labs
```
backend:
# Use netlify identity as backend
name: git-gateway
branch: master
### enable below lines for github integration ###
# name: github
# repo: surjithctly/neat-starter
media_folder: "hestia-labs/src/static/img"
public_folder: "/static/img"
# Please run "npx netlify-cms-proxy-server" for local backend
local_backend: true
publish_mode: editorial_workflow
collections:
- label: "Blog"
name: "blog"
folder: "hestia-labs/src/posts"
create: true
editor:
preview: false
fields:
- { label: "Title", name: "title", widget: "string" }
- { label: "Description", name: "description", widget: "string" }
- { label: "Author", name: "author", widget: "string" }
- { label: "Publish Date", name: "date", widget: "datetime" }
- { label: "Body", name: "body", widget: "markdown" }
- widget: select
label: "tags"
name: "tags"
multiple: true
create: true
options: ["Tags", "created", "from", "config.yml"]
- label: "Settings"
name: "settings"
editor:
preview: false
files:
- label: "Navigation"
name: "items"
file: "hestia-labs/src/_data/navigation.yaml"
fields:
- label: Nav Items
name: items
widget: list
allow_add: false
collapsed: false
fields:
- { label: Title, name: text, widget: string }
- { label: URL, name: url, widget: string }
- label: "Quick Links"
name: "links"
file: "hestia-labs/src/_data/quicklinks.yaml"
fields:
- label: Nav Items
name: links
widget: list
collapsed: false
fields:
- { label: Title, name: title, widget: string }
- { label: URL, name: url, widget: string }
- { label: Description, name: desc, widget: string }
- label: "Meta Settings"
name: "settings"
file: "hestia-labs/src/_data/settings.yaml"
fields:
- { label: Name, name: name, widget: string }
- { label: Author, name: author, widget: string }
- { label: URL, name: url, widget: string }
```
Contributor guide
Assessment
This issue has not been assessed yet.