Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sandpack-id): generate new bundler id based on client version #1202

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading