Skip to content

Comments

refactor(wasm): remove native wasm helper plugin usage#21566

Merged
sapphi-red merged 2 commits intomainfrom
02-05-refactor_plugin_remove_native_wasm_helper_plugin_usage
Feb 5, 2026
Merged

refactor(wasm): remove native wasm helper plugin usage#21566
sapphi-red merged 2 commits intomainfrom
02-05-refactor_plugin_remove_native_wasm_helper_plugin_usage

Conversation

@shulaoda
Copy link
Member

@shulaoda shulaoda commented Feb 5, 2026

Prepare for #21102

I noticed it introduces a ⁨⁨renderChunk⁩⁩ hook where it calls ⁨⁨chunk.viteMetadata!.importedAssets.add(cleanUrl(file))⁩⁩. Since the ⁨⁨viteMetadata⁩⁩ on the chunk is stored on the JS side, this means I have to use a JS-side plugin to patch ⁨⁨renderChunk⁩⁩.
Additionally, the ⁨load⁩ hook in ⁨wasmHelperPlugin⁩ uses ⁨fileToUrl⁩, which introduces differences from ⁨nativeWasmHelperPlugin⁩ and can even lead to some issues.

async function fileToBuiltUrl(
pluginContext: PluginContext,
id: string,
skipPublicCheck = false,
forceInline?: boolean,
): Promise<string> {
const environment = pluginContext.environment
const topLevelConfig = environment.getTopLevelConfig()
if (!skipPublicCheck) {
const publicFile = checkPublicFile(id, topLevelConfig)
if (publicFile) {
if (inlineRE.test(id)) {
// If inline via query, re-assign the id so it can be read by the fs and inlined
id = publicFile
} else {
return publicFileToBuiltUrl(id, topLevelConfig)
}
}
}
const cache = assetCache.get(environment)!
const cached = cache.get(id)
if (cached) {
return cached
}
let { file, postfix } = splitFileAndPostfix(id)
const content = await fsp.readFile(file)
let url: string
if (
shouldInline(environment, file, id, content, pluginContext, forceInline)
) {
url = assetToDataURL(environment, file, content)
} else {
// emit as asset
const originalFileName = normalizePath(
path.relative(environment.config.root, file),
)
const referenceId = pluginContext.emitFile({
type: 'asset',
// Ignore directory structure for asset file names
name: path.basename(file),
originalFileName,
source: content,
})
if (environment.config.command === 'build' && noInlineRE.test(postfix)) {
postfix = postfix.replace(noInlineRE, '').replace(/^&/, '?')
}
if (
environment.config.command === 'serve' &&
environment.config.experimental.bundledDev
) {
const outputFilename = pluginContext.getFileName(referenceId)
url = toOutputFilePathInJSForBundledDev(environment, outputFilename)
} else {
url = `__VITE_ASSET__${referenceId}__${postfix ? `$_${postfix}__` : ``}`
}
}
cache.set(id, url)
return url
}

@shulaoda shulaoda requested a review from sapphi-red February 5, 2026 07:52
@shulaoda shulaoda marked this pull request as draft February 5, 2026 07:57
@shulaoda shulaoda marked this pull request as ready for review February 5, 2026 07:59
@sapphi-red sapphi-red changed the title refactor(plugin): remove native wasm helper plugin usage refactor(wasm): remove native wasm helper plugin usage Feb 5, 2026
@sapphi-red sapphi-red added the p1-chore Doesn't change code behavior (priority) label Feb 5, 2026
@sapphi-red sapphi-red merged commit 71a86be into main Feb 5, 2026
22 of 23 checks passed
@sapphi-red sapphi-red deleted the 02-05-refactor_plugin_remove_native_wasm_helper_plugin_usage branch February 5, 2026 08:11
graphite-app bot pushed a commit to rolldown/rolldown that referenced this pull request Feb 5, 2026
Related to vitejs/vite#21566

This is because vitejs/vite#21102 will refactor the logic around `wasmHelperPlugin`, and `nativeWasmHelperPlugin` is not aligned with the `fileToUrl` behavior. So I plan to remove it for now and re-port it when it’s needed again later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p1-chore Doesn't change code behavior (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants