Skip to content

Conversation

@KimCookieYa
Copy link
Contributor

Problem

  • Users encounter “Failed to construct 'URL': Invalid base URL” when clicking the “View source” action in DevTools if the underlying base URL is invalid.
  • This exception originates from new URL(relative, base) and bubbles up, interrupting the DevTools UI.
  • Fixes GitHub issue #34317

Solution

  • Wrap URL construction to:
    • First try new URL(sourceMapAt, sourceURL).
    • If that fails, try new URL(sourceMapAt) as an absolute URL.
    • If both fail, return null (no symbolication) rather than throwing.
  • This preserves normal behavior for valid bases and absolute URLs, while avoiding crashes for invalid bases.

Implementation details

  • Updated symbolicateSource in packages/react-devtools-shared/src/symbolicateSource.js to handle invalid base URL scenarios without throwing.
  • Added/verified tests in packages/react-devtools-shared/src/__tests__/utils-test.js:
    • “should not throw for invalid base URL with relative source map” → resolves to null.
    • “should resolve absolute source map even if base URL is invalid” → still resolves correctly.

Test plan

  • Lint/format:
    • yarn prettier-check
    • yarn linc
  • Type checking:
    • yarn flow dom-node
  • Unit tests:
    • yarn test --watchAll=false utils-test
    • Optionally: yarn test --watchAll=false utils-test inspectedElement
  • All of the above pass locally for experimental channel.

Risks and rollout

  • Risk: Low. Only affects cases where the base URL is invalid.
  • Normal cases (valid base or absolute sourceMappingURL) are unchanged.
  • No user-facing API changes; DevTools UX becomes more resilient.

Affected packages

  • react-devtools-shared

Related

Checklist

  • Ran yarn prettier-check
  • Ran yarn linc
  • Ran yarn flow dom-node
  • Relevant unit tests passing
  • Linked issue and added a concise summary

Summary

How did you test this change?

@meta-cla meta-cla bot added the CLA Signed label Sep 6, 2025
Copy link
Contributor

@hoxyq hoxyq left a comment

Choose a reason for hiding this comment

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

Thank you!

@hoxyq hoxyq merged commit c4e2508 into facebook:main Sep 6, 2025
247 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants