-
Notifications
You must be signed in to change notification settings - Fork 17
Description
** Note on the update*
The description here is long, including the demanding rollback procedure if the error occurs, and I still had my own questions as to what the full picture was.
Thus I've worked out a description of what appears to be proper practice to clear up sanity-astro's problems (and for other packages' peerDependency handling??), and added it as a comment below, with a corrected package.json attached.
Describe the bug
In #2150 against @sanity/visual-editing, you can find a trail of woe where Presentation ceased to function in Astro, on a previous update of that package. Possibly 2.7.1 may be the breakage point..
However, with the improved package's version 2.8.0, the fix didn't get implemented so that Netlify or Vercel deployments would be repaired for Presentaion, when normally updating with sanity-astro, A contorted list of procedures has been found necessary to get the fix actually to operate in deployments. The apparent reason is in the mixture of config in the @sanity /astro package, which needs to be repaired, as will be described h ere.
To Reproduce
Presumption here is that you are building an app within the monorepo framework provided with the @sanity/astro package. It seems likely that the same error can occur when simply installing the @sanity/astro package in a different project framework.
- have project as described
- update to the fresh @sanity/visual-editing@2.8.0, in the package folder and in each app folder, using ncu -u so that other updated packages such as the client are all up-to-date
- pnpm install from root, which installs in all folders
- test using pnpm run dev, in the app. This works,, as Presentation visual editing can be seen functional.
- now commit and push to the repo which is monitored by Netlify or Vercel so that it redeploys.
- the new deployment will not show improvement, with Presentation still broken, as in 2.7.0 breaks Astro visual editing support visual-editing#2150.
- create an alternative branch using the Astro Node adapter, so that it can be built as well as run preview locally
- this local Node build will also fail Presentation operation, allowing local troubleshooting
Expected behavior
Any of the described builds should have employed the @sanity/visual-editing@2.8.0 fix, and run Presentation properly.
Screenshots
These are available for the failure mode, and the final fix running to be described here, in #2150.
Which versions of Sanity are you using?
All up-to-date, at the points described for failure and fix
What operating system are you using?
Windows 11 very up-to-date, in development mode for local builds due to links
Which versions of Node.js / npm are you running?
$ npm -v && node -v
10.2.4
v20.11.1
Additional context
The error in config has been located and demonstrated to fix Presentation with @sanity/visual-editing@2.8.0, on all three deployment platforms: Netlify, Vercel, and Node locally. Description follows.
- The problem occurs because:
- there is a bogus peerDependency for @sanity/visual-editing in the @sanity/astro packages/sanity-astro package.json. This line is improper, because there is already the primary entry for visual-editing under dependencies. In fact, sanity-astro is the place @sanity/visual-editing is actually used in earnest for program code.
- in the root folder of @sanity/astro monorepo, there are several questionable commands; one of these is
auto-install-peers, which will cause the old version 2.7.1 of visual-editing to be installed along with the 2.8.0 set by ncu -u or manual package.json editing which does not notice the bogus peerDependency. - the result seems to be that pnpm build then connects the old version instead of the updated version when constructing the @sanity-astro package, and/or vite does so in linking the final executable result. Thus this result continues the 2.7.1 version's failures, and Presentation continues to fail, not showing blue outlines, not visual editing, and in fact not connecting the website pane with the editor under Presentation, with the noted console errors visible in the #2150 report.
As a first fix, the auto-install-peers was left alone in .npmrc, in case it had other purposes, and only the improper peerDependency on @sanity/visual-editing was removed from package.json in the monorepo packages/sanity-astro/package.json.
- it was also essential to produce a completely clean package-lock.yaml afterwards. A procedure is available for that under Slack discussion, involving clearing and recreation of package-lock.yaml itself, with all installs.
- this combination was sufficient to repair the problem, so that branches for Netlify, Vercel, and Node could then be committed and thus deployed, then demonstrated with their Presentation Visual Editing fully functional again.
- Vercel required a second manual redeploy from its web console, as described in the Slack item, to clear its on cache so that the corrected install for bulld would actually be done.
All of this is clearly a rather fraught procedure, thus it's suggested that a full fix be done on @sanity/astro, especially as there have been other such configuration errors which have caused great effort in the past.
- all of the above was done on monorepo uses of @sanity/astro, but because of the way pnpm/vite builds make the error, it seems likely the same failure will occur with projects only importing the package from npmjs.
- thus the fixes should not only be applied to source, but @sanity/astro should be published in a fresh version
- suggested fixes are:
- clearly, the improper peerDependency for @sanity/visual-editing should be removed from package.json in packages/sanity-astro of the monorepo, as above demonstrates this as an immediate first fix
- but also, a close examination should be done of root/.npmrc, and very likely at least the
auto-install-peerscommand should be removed. - this .npmrc, as in past errors, appears that it may have been just a paste of boilerplate from a distant project, and so a person very familiar with pnpm should analyze and see if any of its commands are appropriate, of course the unnecessary removed, or that the removal of the entire .npmrc file itself may be best.
For any investigation uses, there are branches listed on a fork of @sanity/astro for each of the Netlify, Vercel, and Node deployments at success and showing some steps leading from fail to success, noted in the comment flow of sanity-io/visual-editing#2150.