Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter committed Dec 7, 2024
1 parent d633af9 commit 65edab6
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/plugin-assets-retry/src/runtime/initialChunkRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare global {
var __RB_ASYNC_CHUNKS__: Record<string, boolean>;
}

// this function is the same as async chunk retry
function findCurrentDomain(url: string, domainList: string[]) {
let domain = '';
for (let i = 0; i < domainList.length; i++) {
Expand All @@ -33,6 +34,7 @@ function findCurrentDomain(url: string, domainList: string[]) {
return domain || window.origin;
}

// this function is the same as async chunk retry
function findNextDomain(url: string, domainList: string[]) {
const currentDomain = findCurrentDomain(url, domainList);
const index = domainList.indexOf(currentDomain);
Expand Down Expand Up @@ -248,10 +250,7 @@ function retry(config: RuntimeRetryOptions, e: Event) {
target.dataset.rsbuildOriginalQuery ?? getQueryFromUrl(url);

// this function is the same as async chunk retry
function getUrlRetryQuery(
existRetryTimes: number,
originalQuery: string,
): string {
function getUrlRetryQuery(existRetryTimes: number): string {
if (config.addQuery === true) {
return originalQuery !== ''
? `${originalQuery}&retry=${existRetryTimes}`
Expand All @@ -269,11 +268,10 @@ function retry(config: RuntimeRetryOptions, e: Event) {
domain: string,
nextDomain: string,
existRetryTimes: number,
originalQuery: string,
) {
return (
cleanUrl(currRetryUrl.replace(domain, nextDomain)) +
getUrlRetryQuery(existRetryTimes + 1, originalQuery)
getUrlRetryQuery(existRetryTimes + 1)
);
}

Expand All @@ -283,7 +281,7 @@ function retry(config: RuntimeRetryOptions, e: Event) {
(target as HTMLScriptElement).defer;

const attributes: ScriptElementAttributes = {
url: getNextRetryUrl(url, domain, nextDomain, existRetryTimes, originalQuery),
url: getNextRetryUrl(url, domain, nextDomain, existRetryTimes),
times: existRetryTimes + 1,
crossOrigin: config.crossOrigin,
isAsync,
Expand Down

0 comments on commit 65edab6

Please sign in to comment.