Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Marc Glasser <marc.aaron.glasser@gmail.com>
  • Loading branch information
kidroca and marcaaron authored Jan 25, 2023
1 parent 93df02a commit 7e2d106
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions packages/react-native-web/src/exports/Image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,16 @@ const ImageWithHeaders: ImageComponent = React.forwardRef((props, ref) => {
const { onError, onLoadStart, onLoadEnd } = props;

React.useEffect(() => {
if (!hasSourceDiff(nextSource, request.current.source)) return;
if (!hasSourceDiff(nextSource, request.current.source)) {
return;
}

// When source changes we want to clean up any old/running requests
request.current.cancel();

if (onLoadStart) onLoadStart();
if (onLoadStart) {
onLoadStart();
}

request.current = ImageLoader.loadWithHeaders(nextSource);

Expand All @@ -383,8 +387,10 @@ const ImageWithHeaders: ImageComponent = React.forwardRef((props, ref) => {

const propsToPass = {
...props,

// Omit `onLoadStart` because we trigger it in the current scope
onLoadStart: undefined,

// Until the current component resolves the request (using headers)
// we skip forwarding the source so the base component doesn't attempt
// to load the original source
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native-web/src/modules/ImageLoader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ const ImageLoader = {
},
loadWithHeaders(source: ImageSource): LoadRequest {
let uri: string;
const abortCtrl = new AbortController();
const abortController = new AbortController();
const request = new Request(source.uri, {
headers: source.headers,
signal: abortCtrl.signal
signal: abortController.signal
});
request.headers.append('accept', 'image/*');

Expand All @@ -175,7 +175,7 @@ const ImageLoader = {
promise,
source,
cancel: () => {
abortCtrl.abort();
abortController.abort();
URL.revokeObjectURL(uri);
}
};
Expand Down

0 comments on commit 7e2d106

Please sign in to comment.