Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): specific error when dev server is stopped #7476

Merged
merged 17 commits into from
Sep 30, 2024

Conversation

jordanl17
Copy link
Member

Description

Currently when the dev server is stopped, when the next error is thrown (for example a new lazy bundle is fetched), then an error failed to fetch dynamic import is thrown and displayed. It doesn't make it clear that this has happened because dev server has gone away.

Now, immediately once the dev server is stopped, the studio will show an error boundary stating such.

Screenshot 2024-09-09 at 11 16 08

What to review

  • The logic to listen to the vite hmr server in DevServerStopped.tsx
  • How DevServerStopped is lazy imported to avoid adding this to the bundle when not in development mode
  • StudioLayout.tsx throwing the dev server stopped error which is causing in studio error boundary, from where the specific screen is shown

Testing

Notes for release

Copy link

vercel bot commented Sep 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 30, 2024 2:25pm
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 30, 2024 2:25pm
test-compiled-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 30, 2024 2:25pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 30, 2024 2:25pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 30, 2024 2:25pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Sep 30, 2024 2:25pm

Copy link
Contributor

github-actions bot commented Sep 9, 2024

No changes to documentation

Copy link
Contributor

github-actions bot commented Sep 9, 2024

Component Testing Report Updated Sep 30, 2024 2:25 PM (UTC)

✅ All Tests Passed -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 51s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 9s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 31s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 37s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 10s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 3m 0s 0 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 43s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 43s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 17s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 8s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 26s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 36s 12 0 0
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

@jordanl17 jordanl17 marked this pull request as ready for review September 9, 2024 10:41
@jordanl17 jordanl17 requested a review from a team as a code owner September 9, 2024 10:41
@jordanl17 jordanl17 requested review from juice49 and removed request for a team September 9, 2024 10:41
Copy link
Contributor

@juice49 juice49 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool feature 🙌. Left some thoughts about non-Vite support and minimising connections and custom code.

packages/sanity/src/core/studio/StudioErrorBoundary.tsx Outdated Show resolved Hide resolved
packages/sanity/src/core/studio/DevServerStopped.tsx Outdated Show resolved Hide resolved
packages/sanity/src/core/studio/StudioLayout.tsx Outdated Show resolved Hide resolved
useEffect(() => {
// no early return to optimize tree-shaking
if (isViteServer(serverHot)) {
serverHot.on('vite:ws:disconnect', markDevServerStopped)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juice49 using import.meta.hot.on. In our version of vite (4.x) there is no .off, however there is in 5.x. Don't think it's a big issue here, since restarting the server will trigger a refresh on the client. But does raise a question around us upgrading perhaps... one for another time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting omission from the v4 API 🤔. Do you have any concerns around creating multiple subscriptions that are never cleaned up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not concerned around multiple subscriptions since starting the server again causing a remounting of the entire app, clearing all existing listeners

@jordanl17
Copy link
Member Author

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] None +1 259 kB osrg
View full report↗︎

Added to transform import.meta in jest cjs environment

bjoerge
bjoerge previously approved these changes Sep 27, 2024
Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, @jordanl17!

@juice49
Copy link
Contributor

juice49 commented Sep 30, 2024

I checked it out to test, but I'm not sure this is working exactly as intended. As soon as I stop the dev server, an uncaught ViteDevServerStoppedError is caught by the top-level Studio error boundary. It doesn't seem to show the specialised "dev server stopped" error message:

Screenshot 2024-09-30 at 11 32 09

When subsequently navigating elsewhere (with dev server still stopped), I saw the Failed to fetch dynamically imported module error:

Screenshot 2024-09-30 at 11 32 31

@jordanl17
Copy link
Member Author

I checked it out to test, but I'm not sure this is working exactly as intended. As soon as I stop the dev server, an uncaught ViteDevServerStoppedError is caught by the top-level Studio error boundary. It doesn't seem to show the specialised "dev server stopped" error message:

Screenshot 2024-09-30 at 11 32 09 When subsequently navigating elsewhere (with dev server still stopped), I saw the `Failed to fetch dynamically imported module` error: Screenshot 2024-09-30 at 11 32 31

@juice49 right you are, I'd forgotten to commit the final commit to rename a few things which was causing this. Note however that navigating away from the initial 'dev server stopped' error will still show the dynamic import error. It would be possible to rectify this, but I can't think of how besides complicating the current setup, which doesn't feel appropriate given this is meant to just be an incremental dev experience improvement

Copy link
Contributor

@juice49 juice49 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant! Looks great to me 🥳.

(Noted and agree with you on the dynamic import error; just wanted to mention it in case it provided useful context).

@jordanl17 jordanl17 added this pull request to the merge queue Sep 30, 2024
Merged via the queue into next with commit 7fcf22a Sep 30, 2024
50 checks passed
@jordanl17 jordanl17 deleted the sdx-1576-dev-server-stop-error-simplified branch September 30, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants