-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Describe the bug
When using the editorial workflow with GitLab (likely affects all backends), the "View Preview" button can show a stale production URL instead of the actual deploy preview URL — or instead of showing nothing at all.
Root cause
The DEPLOY_PREVIEW_FAILURE case in the deploys reducer only sets isFetching: false but does not clear the previous url and status:
case DEPLOY_PREVIEW_FAILURE: {
const { collection, slug } = action.payload;
state[`${collection}.${slug}`].isFetching = false;
break;
}This means the old state from a previous DEPLOY_PREVIEW_SUCCESS (or getDeploy for published entries) persists in the Redux store.
Reproduction flow
- Open an existing published entry in the CMS editor
getDeployruns → stores{ url: "https://production-site.example.com/...", status: "SUCCESS" }in Redux- User saves → creates a
cms/*branch → CI pipeline starts building a preview componentDidUpdatetriggersloadDeployPreview({ maxAttempts: 3 })which polls for commit statuses- If no commit status exists yet (CI hasn't posted one),
getDeployPreviewreturnsnull DEPLOY_PREVIEW_FAILUREis dispatched → only setsisFetching: false- Old
{ status: "SUCCESS", url: "https://production-site.example.com/..." }remains in Redux renderDeployPreviewControlsseesstatus === 'SUCCESS'and renders the "View Preview" link pointing to the production URL, not the deploy preview
Expected behavior
When DEPLOY_PREVIEW_FAILURE fires, the stale url and status should be cleared so that no misleading "View Preview" link is shown:
case DEPLOY_PREVIEW_FAILURE: {
const { collection, slug } = action.payload;
const key = `${collection}.${slug}`;
state[key].isFetching = false;
state[key].url = undefined;
state[key].status = undefined;
break;
}Workaround
We work around this by having our CI pipeline post a running commit status with target_url immediately when a cms/* branch is pushed. This ensures the first or second poll finds a status, causing DEPLOY_PREVIEW_SUCCESS with state: "OTHER" to overwrite the stale SUCCESS, which makes the toolbar show the "Check for Preview" refresh button instead of the misleading production link.
Applicable versions
- decap-cms 3.10.0
- GitLab backend
publish_mode: editorial_workflowpreview_contextconfigured
Environment
- Browser: Chrome
- OS: macOS