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: timestamp config dynamicImport #13502

Merged
merged 1 commit into from
Jun 13, 2023
Merged
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
8 changes: 7 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,10 +1144,16 @@ async function loadConfigFromBundledFile(
// convert to base64, load it with native Node ESM.
if (isESM) {
try {
// Postfix the bundled code with a timestamp to avoid Node's ESM loader cache
const configTimestamp = `${fileName}.timestamp:${Date.now()}-${Math.random()
.toString(16)
.slice(2)}`
return (
await dynamicImport(
'data:text/javascript;base64,' +
Buffer.from(bundledCode).toString('base64'),
Buffer.from(`${bundledCode}\n//${configTimestamp}`).toString(
'base64',
),
Comment on lines +1154 to +1156
Copy link
Member

@bluwy bluwy Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this would affect sourcemaps since we're bundling with esbuild with sourcemap: 'inline', but I'm also not sure if we're using the sourcemap in anyway 🤔

Other than that this looks good to me though, nice find with the issue! I also wonder if doing a { ...config } would also fix the issue if it's an object. (Actually I think we'd need a deep clone)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, I also thought of trying to do a deep clone. Or reviewing our code to avoid modifying the config somehow. But doing a new import here seems safer. The config could have side effects like a variable with a timestamp that won't be unique per config. State could be shared if they are defined as global for example.

)
).default
} catch (e) {
Expand Down