Skip to content

Commit

Permalink
fix: multiple hash loader with different color renders as the same co…
Browse files Browse the repository at this point in the history
…lor (#602)

* fix-hash

* fix

* fix

* fix

* fix

* fix
  • Loading branch information
davidhu2000 committed Jun 26, 2024
1 parent ef64753 commit ae4a2c5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
pages: write
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ umd
.yarn/cache
.yarn/install-state.gz
stories/*.tsx
storybook-static
storybook-static
coverage
2 changes: 1 addition & 1 deletion src/helpers/animation.server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ describe("animation", () => {
"0% {left: -35%;right: 100%} 60% {left: 100%;right: -90%} 100% {left: 100%;right: -90%}",
"my-suffix"
);
expect(name).toEqual("react-spinners-TestLoader-my-suffix");
expect(name).toMatch(/^react-spinners-TestLoader-my-suffix/);
});
});
2 changes: 1 addition & 1 deletion src/helpers/animation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ describe("createAnimation", () => {
"0% {left: -35%;right: 100%} 60% {left: 100%;right: -90%} 100% {left: 100%;right: -90%}",
"my-suffix"
);
expect(name).toEqual("react-spinners-TestLoader-my-suffix");
expect(name).toMatch(/^react-spinners-TestLoader-my-suffix/);
});
});
14 changes: 13 additions & 1 deletion src/helpers/animation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const createAnimation = (loaderName: string, frames: string, suffix: string): string => {
const animationName = `react-spinners-${loaderName}-${suffix}`;
const animationName = `react-spinners-${loaderName}-${suffix}-${animationSuffix(10)}`;

if (typeof window == "undefined" || !window.document) {
return animationName;
Expand All @@ -21,3 +21,15 @@ export const createAnimation = (loaderName: string, frames: string, suffix: stri

return animationName;
};

function animationSuffix(length: number) {
let result = "";
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
return result;
}

0 comments on commit ae4a2c5

Please sign in to comment.