microsoft / microsoft/monaco-editor

[Bug] Unable to access redirected JSON Schema URL

Open
#4,328 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

No response

Monaco Editor Playground Code
var jsonCode = [
	"{",
	'    "$schema": "https://schemas.wp.org/trunk/theme.json",',
	"}"
].join("\n");
var modelUri = monaco.Uri.parse("a://b/foo.json"); // a made up unique URI for our model
var model = monaco.editor.createModel(jsonCode, "json", modelUri);

monaco.languages.json.jsonDefaults.setDiagnosticsOptions( {
	validate: true,
	allowComments: false,
	enableSchemaRequest: true,
} );

monaco.editor.create(document.getElementById("container"), {
	model: model,
});
Reproduction Steps
  • Switch Example in Monaco Editor Playground to "Configure Json Defaults".
  • Paste the code.
Actual (Problematic) Behavior

Editor says "Unable to load schema from 'https://schemas.wp.org/trunk/theme.json': Failed to fetch."

Expected Behavior

Read the JSON Schema URL and validation should work.

Additional Context

This may not be a bug, but it seems like it's not correctly reading JSON Schema URLs with 301 redirects applied.

The schema URL I tested is https://schemas.wp.org/trunk/theme.json, which redirects to https://raw.githubusercontent.com/WordPress/gutenberg/trunk/schemas/json/theme.json.

You can check the redirect trace results with https://wheregoes.com/trace/2024102008/.

  • The same problem can be reproduced with vscode.dev.
  • Works correctly in VS Code Desktop
❌ URL before being redirected

image

✅ URL after being redirected

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Configure Json Defaults playground example and the JSON diagnostics path enabled by enableSchemaRequest. Reproduce the failure with the schemas.wp.org URL, compare it with the redirected raw.githubusercontent.com URL, and verify that the original URL loads and validation works after the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.