adobe / adobe/aem-react-editable-components
[bug] fetchModel fails when host and cqPath is passed
- Dominant language
- TypeScript
- Stars
- 68
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
fetchModel functions failes to get the model when host and cqPath are passed as the url formed to fetch is incorrect
**Package version**
v2.1.0
**To Reproduce**
Steps to reproduce the behavior:
1. invoke fetchModel({
cqPath,
host
})
where cqPath can be any path which can give json
and host where this can be used
example : fetch('https:/api.mockfly.dev/mocks/1a7495c9-1442-415f-b55c-5f5b3a2ed5f4/my-iqos-header.model.json')
**Expected behavior**
The fetch url should be correctly formed and work as expected to download json
in fetchModel.ts at line 58
const hostURL = sanitizeUrl(`${host}/${path}`).replace(/\/+/g, '/'); is the one causing the problem of replacing https:// to http:/ and due to which fetch for model.json fails
Better to replace this with
const fullUrl = new URL(cqPath, host).toString(); which gives the correct url
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Additional context**
Add any other context about the problem here.
Contributor guide
Research direction
Inspect fetchModel.ts at line 58 and reproduce fetchModel({ cqPath, host }) with the provided URL example. Done means the formed URL retains https:// and fetchModel successfully downloads the JSON, matching the issue's expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100