Skip to content

Conversation

@laurenashpole
Copy link
Contributor

Description

This PR adds basic styling to CORS and login error messaging. To keep the errors visually consistent, I did that by creating a new generic Error component. I tried to avoid being too heavy handed with the styles since this component will also inherit any CSS in the parent app. For example, I didn't set colors since we can't know what background the user has chosen or if they're supporting light and dark modes. I've kept the link/button styling as simple as possible and I'm using pixels instead of em or rem since we can't control the parent. I did set a font family because anything seemed better than Times New Roman.

I also removed a bit of code introduced in this PR because, after talking with @ryanbonial, we realized the query error state wasn't updating and wasn't needed for rendering the CORS error.

What to review

  • Make sure the new Error.tsx and Error.styles.ts files look okay. Open to any feedback on how I'm exporting inline styles or the props I'm passing to the component.
  • In LoginError.tsx and CorsErrorComponent.tsx, check that the correct props are being passed.
  • Everywhere else, double check that I'm not deleting anything I shouldn't be.

Testing

Since these changes are mostly visual, I didn't add automated tests but did do manual testing. I looked at Kitchen Sink and the test SDK Movie Procurement app in light and dark modes and made sure the "Retry" and "Manage CORS Configuration" CTAs works as expected. Note, the Kitchen Sink app will also render an uncaught error overlay which I'm hiding in the screenshots below. I think it only happens there but we should keep an eye out.

Kitchen Sink SDK Movie Procurement App
Screenshot 2025-10-02 at 1 00 49 PM Screenshot 2025-10-02 at 1 08 02 PM
Screenshot 2025-10-02 at 1 01 11 PM Screenshot 2025-10-02 at 1 07 40 PM
Screenshot 2025-10-02 at 1 05 12 PM Screenshot 2025-10-02 at 1 09 50 PM
Screenshot 2025-10-02 at 1 05 33 PM Screenshot 2025-10-02 at 1 10 15 PM

To re-create the CORS error locally, I updated vite.config.ts in the Kitchen Sink app with port 3339 and ran pnpm dev -- --port=3339. For the login error, I updated the getTokenFromLocation function in the auth utils.ts file to return an invalid token.

Fun gif

Meme with the text "Programmers, When they finally get a different error message"

@laurenashpole laurenashpole requested a review from a team as a code owner October 2, 2025 17:14
@vercel
Copy link

vercel bot commented Oct 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sdk-docs Ready Ready Preview Comment Oct 2, 2025 8:32pm
sdk-kitchensink-react Ready Ready Preview Comment Oct 2, 2025 8:32pm

@@ -0,0 +1,35 @@
const FONT_SANS_SERIF = `-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I stole these font choices from the uncaught error overlay in the sanity repo. I'm not sure if this is the best place for them but I put them here for now since it's the only styles file.

Copy link
Member

@colepeters colepeters left a comment

Choose a reason for hiding this comment

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

Yaaaaas, first PR! Thanks Lauren! A few questions for discussion, but this looks great!

Comment on lines 21 to 22
heading="Before you continue..."
description="To access your content, you need to <b>add the following URL as a CORS origin</b> to your Sanity project."
Copy link
Member

Choose a reason for hiding this comment

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

Couple minor typographic/semantic nits (I know this code was inherited, all good!):

Suggested change
heading="Before you continue..."
description="To access your content, you need to <b>add the following URL as a CORS origin</b> to your Sanity project."
heading="Before you continue"
description="To access your content, you need to <strong>add the following URL as a CORS origin</strong> to your Sanity project."

Copy link
Member

Choose a reason for hiding this comment

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

Feel free to adjust the wording in any way too.

message?: string
}

export function Error({heading, description, code, cta, message}: ErrorProps): React.ReactNode {
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if it would make sense for the description, code, and message props to be collapsed into a children prop, and just composing the necessary content with each instance where the Error component is used. This would mean having to import and use the styles wherever the component is used, but maybe that also keeps the component itself a little more flexible/reusable? What do you think? (Totally open ended on this!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that since those do feel like a lot of similar props but I also liked the idea that the component could be dropped in anywhere without having to think about its styling.

One thing I'm realizing as I test out the message field is that it repeats some of the information included in description and code and doesn't really flow all that well (also I'm wondering how often we'd even end up without a projectId and needing to use it). Maybe it would make sense to move that to the description and delete message altogther.

Copy link
Member

Choose a reason for hiding this comment

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

Good points all around! Let's maybe converge some of this on description in that case as you suggest 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed up consolidating fields and the copy updates from above.

colepeters
colepeters previously approved these changes Oct 2, 2025
Copy link
Member

@colepeters colepeters left a comment

Choose a reason for hiding this comment

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

Yes chef!

Copy link
Member

@ryanbonial ryanbonial left a comment

Choose a reason for hiding this comment

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

yay

@laurenashpole laurenashpole merged commit 3bf96f2 into main Oct 2, 2025
18 checks passed
@laurenashpole laurenashpole deleted the la/cors-error-styling branch October 2, 2025 21:18
@squiggler squiggler bot mentioned this pull request Sep 25, 2025
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