From 8d1300297af02c9338a7707d22d7ea3763f59475 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 5 Jul 2023 12:04:23 -0700 Subject: [PATCH 01/11] Add saveAssetPlugin to fix long path assets --- .../react-native-win32/react-native.config.js | 1 + .../react-native-win32/saveAssetPlugin.js | 45 +++++++++++++++++++ .../src/Libraries/Image/assetPaths.js | 32 +++++++++++++ .../Image/resolveAssetSource.win32.js | 15 ++++--- 4 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 packages/@office-iss/react-native-win32/saveAssetPlugin.js create mode 100644 packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js diff --git a/packages/@office-iss/react-native-win32/react-native.config.js b/packages/@office-iss/react-native-win32/react-native.config.js index dacf5861050..004d4f12615 100644 --- a/packages/@office-iss/react-native-win32/react-native.config.js +++ b/packages/@office-iss/react-native-win32/react-native.config.js @@ -7,6 +7,7 @@ module.exports = { projectConfig: (projectRoot, projectParams) => null, dependencyConfig: (projectRoot, dependencyParams) => null, npmPackageName: '@office-iss/react-native-win32', + saveAssetsPlugin: '@office-iss/react-native-win32/saveAssetPlugin' }, }, }; diff --git a/packages/@office-iss/react-native-win32/saveAssetPlugin.js b/packages/@office-iss/react-native-win32/saveAssetPlugin.js new file mode 100644 index 00000000000..7c5bad140a3 --- /dev/null +++ b/packages/@office-iss/react-native-win32/saveAssetPlugin.js @@ -0,0 +1,45 @@ +// @ts-check +const path = require('path'); +const ensureSmallPath = require('./Libraries/Image/assetPaths'); + +/** + * @typedef {import("metro").AssetData} AssetData; + **/ + +/** + * @param {AssetData} asset + * @param {number} scale + * @returns {string} + */ +function getAssetDestPath(asset, scale) { + const suffix = scale === 1 ? '' : `@${scale}x`; + const fileName = `${asset.name + suffix}.${asset.type}`; + return path.join( + // Assets can have relative paths outside of the project root. + // Replace `../` with `_` to make sure they don't end up outside of + // the expected assets directory. + ensureSmallPath(asset.httpServerLocation.substr(1).replace(/\.\.\//g, '_')), + fileName, + ); +} + +/** + * @param {ReadonlyArray} assets + * @param {string} _platform + * @param {string | undefined} _assetsDest + * @param {string | undefined} _assetCatalogDest + * @param {(asset: AssetData, allowedScales: number[] | undefined, getAssetDestPath: (asset: AssetData, scale: number) => string) => void} addAssetToCopy + */ +function saveAssetsWin32( + assets, + _platform, + _assetsDest, + _assetCatalogDest, + addAssetToCopy, +) { + assets.forEach((asset) => + addAssetToCopy(asset, undefined, getAssetDestPath), + ); +} + +module.exports = saveAssetsWin32; \ No newline at end of file diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js b/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js new file mode 100644 index 00000000000..a47197cf74a --- /dev/null +++ b/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js @@ -0,0 +1,32 @@ +/** + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * @flow strict-local + * @format + */ + +'use strict'; + +function ensureSmallPath(str) { + if (str.length < 40) return str; + + const assetsPrefix = 'assets/'; + + if (!str.startsWith(assetsPrefix)) { + console.warn(`Unexpected asset uri - ${str} may not load correctly.`); + } + + str = str.slice(assetsPrefix.length); + var hash = 0, + i, + chr; + for (i = 0; i < str.length; i++) { + chr = str.charCodeAt(i); + hash = (hash << 5) - hash + chr; + hash |= 0; // Convert to 32bit integer + } + return assetsPrefix + hash.toString(); +} + +module.exports = ensureSmallPath; diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js b/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js index d6db1868a96..9ebf2f4c517 100644 --- a/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js +++ b/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js @@ -10,6 +10,7 @@ const resolveAssetSource = require('./resolveAssetSource.js'); // Get base impl const Platform = require('../Utilities/Platform'); +const ensureSmallPath = require('./assetPaths.js'); type IPackagerAsset = { __packager_asset: boolean, @@ -56,7 +57,7 @@ class AssetResolverLateScaleResolution { */ _scaledAssetURLInBundle() { const path = this._resolver.bundleUrl || 'file://'; - return this._fromSource(path + this._getAssetPath()); + return this._fromSource(path + this._getAssetPath(true)); } /** @@ -66,7 +67,7 @@ class AssetResolverLateScaleResolution { _assetServerURL() { return this._fromSource( this._resolver.serverUrl + - this._getAssetPath() + + this._getAssetPath(false) + '?platform=' + Platform.OS + '&hash=' + @@ -77,8 +78,8 @@ class AssetResolverLateScaleResolution { /** * Returns a path like 'assets/AwesomeModule/icon.png' */ - _getAssetPath(): string { - const assetDir = this._getBasePath(); + _getAssetPath(local: boolean): string { + const assetDir = this._getBasePath(local); return ( assetDir + '/' + @@ -88,7 +89,11 @@ class AssetResolverLateScaleResolution { ); } - _getBasePath() { + _getBasePath(local: boolean) { + if (local) { + return ensureSmallPath(this._resolver.asset.httpServerLocation.substr(1).replace(/\.\.\//g, '_')); + } + let basePath = this._resolver.asset.httpServerLocation; if (basePath[0] === '/') { basePath = basePath.substr(1); From 39533b53088a2979b55f695345814d9ff5ab4416 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 5 Jul 2023 12:04:34 -0700 Subject: [PATCH 02/11] Change files --- ...-native-win32-43b80e6f-96e4-479c-b4d7-46c1fb056647.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@office-iss-react-native-win32-43b80e6f-96e4-479c-b4d7-46c1fb056647.json diff --git a/change/@office-iss-react-native-win32-43b80e6f-96e4-479c-b4d7-46c1fb056647.json b/change/@office-iss-react-native-win32-43b80e6f-96e4-479c-b4d7-46c1fb056647.json new file mode 100644 index 00000000000..cbfde873a6f --- /dev/null +++ b/change/@office-iss-react-native-win32-43b80e6f-96e4-479c-b4d7-46c1fb056647.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Add saveAssetPlugin to fix long path assets", + "packageName": "@office-iss/react-native-win32", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} From 4cf790ed1cac4ec12a1b3cc47aa5385941babee6 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 5 Jul 2023 17:09:17 -0700 Subject: [PATCH 03/11] comment --- .../react-native-win32/src/Libraries/Image/assetPaths.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js b/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js index a47197cf74a..0c0911ef063 100644 --- a/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js +++ b/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js @@ -8,6 +8,10 @@ 'use strict'; +// Some windows machines may not have long paths enabled +// https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation +// Assets in nested node_modules (common when using pnpm) - end up creating very long paths +// Using this function we shorten longer paths to prevent paths from hitting the path limit function ensureSmallPath(str) { if (str.length < 40) return str; From c2fb28a36ed5e3e27124e52f8acff3b9d127a78d Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Tue, 8 Aug 2023 09:58:08 -0700 Subject: [PATCH 04/11] add back compat --- .../react-native-win32/metro.config.js | 1 + .../metroLongPathAssetDataPlugin.js | 15 +++++++++++++++ .../react-native-win32/react-native.config.js | 3 ++- .../react-native-win32/saveAssetPlugin.js | 4 ++-- .../src/Libraries/Image/assetPaths.js | 4 ++-- .../Libraries/Image/resolveAssetSource.win32.js | 10 ++++++++-- 6 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 packages/@office-iss/react-native-win32/metroLongPathAssetDataPlugin.js diff --git a/packages/@office-iss/react-native-win32/metro.config.js b/packages/@office-iss/react-native-win32/metro.config.js index 3cbf6a97b3d..410234b1915 100644 --- a/packages/@office-iss/react-native-win32/metro.config.js +++ b/packages/@office-iss/react-native-win32/metro.config.js @@ -14,3 +14,4 @@ if ( const {makeMetroConfig} = require('@rnw-scripts/metro-dev-config'); module.exports = makeMetroConfig(); +module.exports.transformer.assetPlugins = [require.resolve('./metroShortPathAssetDataPlugin.js')]; diff --git a/packages/@office-iss/react-native-win32/metroLongPathAssetDataPlugin.js b/packages/@office-iss/react-native-win32/metroLongPathAssetDataPlugin.js new file mode 100644 index 00000000000..a649d234682 --- /dev/null +++ b/packages/@office-iss/react-native-win32/metroLongPathAssetDataPlugin.js @@ -0,0 +1,15 @@ +// @ts-check +/** + * @typedef {import("metro").AssetData} AssetData; + **/ + +/** + * @param {AssetData} asset + * @returns {Promise} + */ +async function metroShortPathAssetDataPlugin(asset) { + asset['__useShortPath'] = true; + return Promise.resolve(asset); + } + +module.exports = metroShortPathAssetDataPlugin; \ No newline at end of file diff --git a/packages/@office-iss/react-native-win32/react-native.config.js b/packages/@office-iss/react-native-win32/react-native.config.js index 004d4f12615..bd812745a5f 100644 --- a/packages/@office-iss/react-native-win32/react-native.config.js +++ b/packages/@office-iss/react-native-win32/react-native.config.js @@ -7,7 +7,8 @@ module.exports = { projectConfig: (projectRoot, projectParams) => null, dependencyConfig: (projectRoot, dependencyParams) => null, npmPackageName: '@office-iss/react-native-win32', - saveAssetsPlugin: '@office-iss/react-native-win32/saveAssetPlugin' + // Enable once CLI config supports it + // saveAssetsPlugin: '@office-iss/react-native-win32/saveAssetPlugin' }, }, }; diff --git a/packages/@office-iss/react-native-win32/saveAssetPlugin.js b/packages/@office-iss/react-native-win32/saveAssetPlugin.js index 7c5bad140a3..c559cdd21a2 100644 --- a/packages/@office-iss/react-native-win32/saveAssetPlugin.js +++ b/packages/@office-iss/react-native-win32/saveAssetPlugin.js @@ -1,6 +1,6 @@ // @ts-check const path = require('path'); -const ensureSmallPath = require('./Libraries/Image/assetPaths'); +const ensureShortPath = require('./Libraries/Image/assetPaths'); /** * @typedef {import("metro").AssetData} AssetData; @@ -18,7 +18,7 @@ function getAssetDestPath(asset, scale) { // Assets can have relative paths outside of the project root. // Replace `../` with `_` to make sure they don't end up outside of // the expected assets directory. - ensureSmallPath(asset.httpServerLocation.substr(1).replace(/\.\.\//g, '_')), + ensureShortPath(asset.httpServerLocation.substr(1).replace(/\.\.\//g, '_')), fileName, ); } diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js b/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js index 0c0911ef063..c155bcdb50d 100644 --- a/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js +++ b/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js @@ -12,7 +12,7 @@ // https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation // Assets in nested node_modules (common when using pnpm) - end up creating very long paths // Using this function we shorten longer paths to prevent paths from hitting the path limit -function ensureSmallPath(str) { +function ensureShortPath(str) { if (str.length < 40) return str; const assetsPrefix = 'assets/'; @@ -33,4 +33,4 @@ function ensureSmallPath(str) { return assetsPrefix + hash.toString(); } -module.exports = ensureSmallPath; +module.exports = ensureShortPath; diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js b/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js index 9ebf2f4c517..2fa5b445a76 100644 --- a/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js +++ b/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js @@ -10,7 +10,7 @@ const resolveAssetSource = require('./resolveAssetSource.js'); // Get base impl const Platform = require('../Utilities/Platform'); -const ensureSmallPath = require('./assetPaths.js'); +const ensureShortPath = require('./assetPaths.js'); type IPackagerAsset = { __packager_asset: boolean, @@ -91,7 +91,13 @@ class AssetResolverLateScaleResolution { _getBasePath(local: boolean) { if (local) { - return ensureSmallPath(this._resolver.asset.httpServerLocation.substr(1).replace(/\.\.\//g, '_')); + const safePath = this._resolver.asset.httpServerLocation.substr(1).replace(/\.\.\//g, '_'); + // If this asset was created with the newer saveAssetPlugin, then we should shorten the path + // This conditional is added to allow back compat of older bundles which might have been created without the saveAssetPlugin + if (this.resolver.asset['__useShortPath']) { + return ensureShortPath(safePath); + } + return safePath; } let basePath = this._resolver.asset.httpServerLocation; From 3b91893b1492189d20c19edbc2b63fb6e18e14be Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Tue, 8 Aug 2023 11:19:35 -0700 Subject: [PATCH 05/11] fix --- packages/@office-iss/react-native-win32/metro.config.js | 1 + ...gPathAssetDataPlugin.js => metroShortPathAssetDataPlugin.js} | 0 packages/@office-iss/react-native-win32/react-native.config.js | 2 +- 3 files changed, 2 insertions(+), 1 deletion(-) rename packages/@office-iss/react-native-win32/{metroLongPathAssetDataPlugin.js => metroShortPathAssetDataPlugin.js} (100%) diff --git a/packages/@office-iss/react-native-win32/metro.config.js b/packages/@office-iss/react-native-win32/metro.config.js index 410234b1915..8f23945a670 100644 --- a/packages/@office-iss/react-native-win32/metro.config.js +++ b/packages/@office-iss/react-native-win32/metro.config.js @@ -14,4 +14,5 @@ if ( const {makeMetroConfig} = require('@rnw-scripts/metro-dev-config'); module.exports = makeMetroConfig(); +// Enable this when RN CLI gets support for saveAssetPlugins: https://github.com/react-native-community/cli/pull/2002 module.exports.transformer.assetPlugins = [require.resolve('./metroShortPathAssetDataPlugin.js')]; diff --git a/packages/@office-iss/react-native-win32/metroLongPathAssetDataPlugin.js b/packages/@office-iss/react-native-win32/metroShortPathAssetDataPlugin.js similarity index 100% rename from packages/@office-iss/react-native-win32/metroLongPathAssetDataPlugin.js rename to packages/@office-iss/react-native-win32/metroShortPathAssetDataPlugin.js diff --git a/packages/@office-iss/react-native-win32/react-native.config.js b/packages/@office-iss/react-native-win32/react-native.config.js index bd812745a5f..6d3aeb41517 100644 --- a/packages/@office-iss/react-native-win32/react-native.config.js +++ b/packages/@office-iss/react-native-win32/react-native.config.js @@ -7,7 +7,7 @@ module.exports = { projectConfig: (projectRoot, projectParams) => null, dependencyConfig: (projectRoot, dependencyParams) => null, npmPackageName: '@office-iss/react-native-win32', - // Enable once CLI config supports it + // Enable once CLI config supports it - https://github.com/react-native-community/cli/pull/2002 // saveAssetsPlugin: '@office-iss/react-native-win32/saveAssetPlugin' }, }, From e0f642287ac0bfa91f60c2812fbf923fb4cd32b5 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 9 Aug 2023 10:38:08 -0700 Subject: [PATCH 06/11] turn off win32 assetPlugin for now --- packages/@office-iss/react-native-win32/metro.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@office-iss/react-native-win32/metro.config.js b/packages/@office-iss/react-native-win32/metro.config.js index 8f23945a670..c27321c5ad2 100644 --- a/packages/@office-iss/react-native-win32/metro.config.js +++ b/packages/@office-iss/react-native-win32/metro.config.js @@ -15,4 +15,4 @@ if ( const {makeMetroConfig} = require('@rnw-scripts/metro-dev-config'); module.exports = makeMetroConfig(); // Enable this when RN CLI gets support for saveAssetPlugins: https://github.com/react-native-community/cli/pull/2002 -module.exports.transformer.assetPlugins = [require.resolve('./metroShortPathAssetDataPlugin.js')]; +// module.exports.transformer.assetPlugins = [require.resolve('./metroShortPathAssetDataPlugin.js')]; From f7c5e9864543d173da095d60602309037caec2d7 Mon Sep 17 00:00:00 2001 From: Andrew Coates Date: Thu, 10 Aug 2023 12:00:57 -0700 Subject: [PATCH 07/11] fix --- .../react-native-win32/metroShortPathAssetDataPlugin.js | 4 ++-- .../src/Libraries/Image/resolveAssetSource.win32.js | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/@office-iss/react-native-win32/metroShortPathAssetDataPlugin.js b/packages/@office-iss/react-native-win32/metroShortPathAssetDataPlugin.js index a649d234682..8e0f9fe19f5 100644 --- a/packages/@office-iss/react-native-win32/metroShortPathAssetDataPlugin.js +++ b/packages/@office-iss/react-native-win32/metroShortPathAssetDataPlugin.js @@ -4,11 +4,11 @@ **/ /** - * @param {AssetData} asset + * @param {AssetData & {__useShortPath: boolean}} asset * @returns {Promise} */ async function metroShortPathAssetDataPlugin(asset) { - asset['__useShortPath'] = true; + asset.__useShortPath = true; return Promise.resolve(asset); } diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js b/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js index 2fa5b445a76..a9cf8121135 100644 --- a/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js +++ b/packages/@office-iss/react-native-win32/src/Libraries/Image/resolveAssetSource.win32.js @@ -91,10 +91,12 @@ class AssetResolverLateScaleResolution { _getBasePath(local: boolean) { if (local) { - const safePath = this._resolver.asset.httpServerLocation.substr(1).replace(/\.\.\//g, '_'); + const safePath = this._resolver.asset.httpServerLocation + .substr(1) + .replace(/\.\.\//g, '_'); // If this asset was created with the newer saveAssetPlugin, then we should shorten the path // This conditional is added to allow back compat of older bundles which might have been created without the saveAssetPlugin - if (this.resolver.asset['__useShortPath']) { + if (this._resolver.asset.__useShortPath) { return ensureShortPath(safePath); } return safePath; From dcde23104c1a0b0f9734ca65325595453367d8ac Mon Sep 17 00:00:00 2001 From: Andrew Coates Date: Thu, 10 Aug 2023 12:21:36 -0700 Subject: [PATCH 08/11] fix --- packages/@office-iss/react-native-win32/overrides.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/@office-iss/react-native-win32/overrides.json b/packages/@office-iss/react-native-win32/overrides.json index d403cf988be..ab6e43638d3 100644 --- a/packages/@office-iss/react-native-win32/overrides.json +++ b/packages/@office-iss/react-native-win32/overrides.json @@ -233,6 +233,10 @@ "baseFile": "packages/react-native/Libraries/DevToolsSettings/DevToolsSettingsManager.android.js", "baseHash": "1c9eb481e8ed077fa650e3ea34837e2a31310366" }, + { + "type": "platform", + "file": "src/Libraries/Image/assetPaths.js" + }, { "type": "derived", "file": "src/Libraries/Image/Image.win32.js", From 327357f6860ab0cf7ade5fc2dccad706e7b86ca3 Mon Sep 17 00:00:00 2001 From: Andrew Coates Date: Thu, 10 Aug 2023 12:53:49 -0700 Subject: [PATCH 09/11] fix --- .../react-native-win32/src/Libraries/Image/assetPaths.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js b/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js index c155bcdb50d..aab0c8ac4ad 100644 --- a/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js +++ b/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js @@ -12,7 +12,7 @@ // https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation // Assets in nested node_modules (common when using pnpm) - end up creating very long paths // Using this function we shorten longer paths to prevent paths from hitting the path limit -function ensureShortPath(str) { +function ensureShortPath(str: string) { if (str.length < 40) return str; const assetsPrefix = 'assets/'; From d3a095c634aecbada07cf9c757876ce90db5d141 Mon Sep 17 00:00:00 2001 From: Andrew Coates Date: Thu, 10 Aug 2023 13:29:55 -0700 Subject: [PATCH 10/11] Change files --- ...ative-windows-c92794d1-18fd-49dc-a15e-a50992c2413c.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-c92794d1-18fd-49dc-a15e-a50992c2413c.json diff --git a/change/react-native-windows-c92794d1-18fd-49dc-a15e-a50992c2413c.json b/change/react-native-windows-c92794d1-18fd-49dc-a15e-a50992c2413c.json new file mode 100644 index 00000000000..073827d1473 --- /dev/null +++ b/change/react-native-windows-c92794d1-18fd-49dc-a15e-a50992c2413c.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Fix CoreApp build failure with latest VS version", + "packageName": "react-native-windows", + "email": "acoates@microsoft.com", + "dependentChangeType": "patch" +} From f508bce6ac0283b831d045750d6ab42eb5964de9 Mon Sep 17 00:00:00 2001 From: Andrew Coates Date: Thu, 10 Aug 2023 13:56:16 -0700 Subject: [PATCH 11/11] fix --- .../react-native-win32/src/Libraries/Image/assetPaths.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js b/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js index aab0c8ac4ad..101f3b25af0 100644 --- a/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js +++ b/packages/@office-iss/react-native-win32/src/Libraries/Image/assetPaths.js @@ -12,7 +12,7 @@ // https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation // Assets in nested node_modules (common when using pnpm) - end up creating very long paths // Using this function we shorten longer paths to prevent paths from hitting the path limit -function ensureShortPath(str: string) { +function ensureShortPath(str: string): string { if (str.length < 40) return str; const assetsPrefix = 'assets/'; @@ -21,12 +21,12 @@ function ensureShortPath(str: string) { console.warn(`Unexpected asset uri - ${str} may not load correctly.`); } - str = str.slice(assetsPrefix.length); + const postStr = str.slice(assetsPrefix.length); var hash = 0, i, chr; - for (i = 0; i < str.length; i++) { - chr = str.charCodeAt(i); + for (i = 0; i < postStr.length; i++) { + chr = postStr.charCodeAt(i); hash = (hash << 5) - hash + chr; hash |= 0; // Convert to 32bit integer }