feat: allow passing HTTP headers to SvgUri#2983
Open
patrickwehbe wants to merge 1 commit into
Open
Conversation
Thread an optional `headers` prop through the URI components so requests
can carry custom HTTP headers, modelled on React Native's
`ImageURISource.headers`. The prop is optional and defaults to the
previous behaviour, so existing usage is unaffected.
`fetchText`/`fetchUriData` now accept an optional headers map and forward
it to `fetch(uri, { headers })`. `headers` is added to `UriProps` and
passed from `SvgUri`, `SvgFromUri`, `SvgCssUri` and `SvgWithCssUri`,
including in the effect/`componentDidUpdate` paths so changing the
headers re-fetches.
Closes software-mansion#2320
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
headersprop to the URI-based components so requests for remote SVGs can carry custom HTTP headers (for example anAuthorizationtoken, or a header that tells the server which variant to return). This is the feature requested in #2320.The prop is modelled on React Native's
ImageURISource.headers, so it should feel familiar to anyone who already sets headers on<Image source={{ uri, headers }} />.Changes
fetchText/fetchUriData(src/utils/fetchData.ts) take an optionalheadersmap and forward it tofetch(uri, { headers }).headers?: Record<string, string>is added toUriPropsinsrc/xml.tsx.SvgUri,SvgFromUri,SvgCssUriandSvgWithCssUri. The effect dependency array and the classcomponentDidUpdatechecks includeheaders, so swapping the headers re-fetches.apps/common/test/Test2320.tsxdemonstrating the prop, and registered it in the test index.Notes
headersis omitted,fetchis called exactly as before.headersobject referentially stable (e.g.useMemo) to avoid re-fetching on every render. The example does this.require()don't go through the network, so they're unaffected.Test plan
yarn tscpasses.yarn lintpasses.apps/common.Closes #2320