Skip to content

Commit

Permalink
fix(sandpack-id): generate new bundler id based on client version (#1202
Browse files Browse the repository at this point in the history
)
  • Loading branch information
danilowoz authored Sep 12, 2024
1 parent e3bd9e7 commit dbb882e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sandpack-client/.bundler
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Manually generated file to trigger new releases based on the bundler changes.
// The following value is the commit hash from codesandbox-client
b7d51d076df01577313c724ab54419ce41667d17
f64b210d3832ce8558516bcda9bebd543400c9d9
3 changes: 3 additions & 0 deletions sandpack-react/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const replace = require("@rollup/plugin-replace");
const typescript = require("@rollup/plugin-typescript");
const filesize = require("rollup-plugin-filesize");

const sandpackClientPkg = require("../sandpack-client/package.json");

const pkg = require("./package.json");
const generateUnstyledTypes = require("./scripts/rollup-generate-unstyled-types");
const removeCss = require("./scripts/rollup-remove-css-transformer");
Expand All @@ -28,6 +30,7 @@ const configBase = [
values: {
"process.env.TEST_ENV": "false",
"process.env.SANDPACK_UNSTYLED_COMPONENTS": `"false"`,
"process.env.SANDPACK_CLIENT_VERSION": `"${sandpackClientPkg.version}"`,
},
}),
typescript({ tsconfig: "./tsconfig.json" }),
Expand Down
6 changes: 5 additions & 1 deletion sandpack-react/src/utils/useAsyncSandpackId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const useSandpackId = () => {
*/
const MAX_ID_LENGTH = 9;

const sandpackClientVersion = process.env.SANDPACK_CLIENT_VERSION;

export const useAsyncSandpackId = (files: SandpackBundlerFiles) => {
if (typeof useReactId === "function") {
/* eslint-disable-next-line react-hooks/rules-of-hooks */
Expand All @@ -27,7 +29,9 @@ export const useAsyncSandpackId = (files: SandpackBundlerFiles) => {
const allCode = Object.entries(files)
.map((path, code) => path + "|" + code)
.join("|||");
const sha = await generateShortId(allCode + reactDomId);
const sha = await generateShortId(
allCode + reactDomId + sandpackClientVersion
);

return ensureLength(
sha.replace(/:/g, "sp").replace(/[^a-zA-Z]/g, ""),
Expand Down

0 comments on commit dbb882e

Please sign in to comment.