curriculum icon indicating copy to clipboard operation
curriculum copied to clipboard

Working with APIs: Clarify default 'cors' mode behavior in CORS section

Open Maddily opened this issue 1 year ago • 3 comments

Because

I wanted to mention the default behavior when sending cross-origin requests using fetch.

This PR

  • Mentions that, in case the request being sent is cross-origin, mode: 'cors'` is set by default.
  • Adds that explicitly specifying mode: 'cors' in the options is good for clarity.

Issue

Closes #XXXXX

Additional Information

N/A

Pull Request Requirements

  • [x] I have thoroughly read and understand The Odin Project curriculum contributing guide
  • [x] The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • [x] The Because section summarizes the reason for this PR
  • [x] The This PR section has a bullet point list describing the changes in this PR
  • [ ] If this PR addresses an open issue, it is linked in the Issue section
  • [ ] If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • [ ] If any lesson files are included in this PR, they follow the Layout Style Guide

Maddily avatar Sep 02 '24 13:09 Maddily

We can actually probably just remove the { mode: 'cors' } bits entirely (from this lesson and a few other lessons in the curriculum) as that's the default mode for fetch. So the CORS section introducing that to "solve a problem" is redundant because there is no problem when omitted.

If you can put this on hold for a bit, I'm discussing with the team regarding some other CORS material because there might be an additional thing we need to do on top of removing the mode options references. I'll get back to you once we've discussed that through.

mao-sz avatar Sep 04 '24 18:09 mao-sz

That makes sense. I'll put this on hold for now and wait for your update after the team discussion.

Maddily avatar Sep 05 '24 05:09 Maddily

@MaoShizhong There was an Issue + PR I opened regarding this in the past. Maybe it is worth looking into why it was closed and not merged Check #23232

Mclilzee avatar Sep 05 '24 16:09 Mclilzee

@wise-king-sullyman Did you ever get round to confirming this in Safari on MacOS? And discussing how CORS can be introduced in the Rails pathway?

mao-sz avatar Nov 23 '24 20:11 mao-sz

My apologies, this slipped through the cracks on me. I just tested in Safari and confirmed that fetch is defaulting to cors mode so I think we should be ok to remove it as @mao-sz suggested.

Would you still be interested in making this change @Maddily? I know it has been quite a while since you opened this PR.

wise-king-sullyman avatar Aug 18 '25 20:08 wise-king-sullyman

@wise-king-sullyman Absolutely. I'm on it.

Maddily avatar Sep 01 '25 07:09 Maddily

@mao-sz I've removed the cors references from this lesson as well as Fetching Data In React and Async and Await. Could you confirm if these were all the lessons that mentioned mode: 'cors', or if I missed any?

Maddily avatar Sep 01 '25 08:09 Maddily