From 14f77dd84d2c0f943f88848e5e3076b135e3b45c Mon Sep 17 00:00:00 2001 From: Danilo Woznica Date: Thu, 5 Sep 2024 13:56:00 +0100 Subject: [PATCH] fix(client): remove non-letter chart from random id --- sandpack-react/src/presets/CustomSandpack.stories.tsx | 2 +- sandpack-react/src/utils/useAsyncSandpackId.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sandpack-react/src/presets/CustomSandpack.stories.tsx b/sandpack-react/src/presets/CustomSandpack.stories.tsx index ce5276ff..6044a2b1 100644 --- a/sandpack-react/src/presets/CustomSandpack.stories.tsx +++ b/sandpack-react/src/presets/CustomSandpack.stories.tsx @@ -55,8 +55,8 @@ export const ExperimentalServiceWorker: React.FC = () => { `, }} options={{ - bundlerURL: "https://nqfrns-3000.csb.app/", experimental_enableServiceWorker: true, + experimental_enableStableServiceWorkerId: true, }} template="react" /> diff --git a/sandpack-react/src/utils/useAsyncSandpackId.ts b/sandpack-react/src/utils/useAsyncSandpackId.ts index b4b0dd81..312bb281 100644 --- a/sandpack-react/src/utils/useAsyncSandpackId.ts +++ b/sandpack-react/src/utils/useAsyncSandpackId.ts @@ -29,7 +29,10 @@ export const useAsyncSandpackId = (files: SandpackBundlerFiles) => { .join("|||"); const sha = await generateShortId(allCode + reactDomId); - return ensureLength(sha.replace(/:/g, "sp"), MAX_ID_LENGTH); + return ensureLength( + sha.replace(/:/g, "sp").replace(/[^a-zA-Z]/g, ""), + MAX_ID_LENGTH + ); }; } else { return () => ensureLength(generateRandomId(), MAX_ID_LENGTH);