Skip to content

Commit 5462a7f

Browse files
committed
fix: rspack resolve importer, unstable_use hint, and empty-deps trusted-hook check
- hookStabilityFor in rspack loader now passes the importer argument through to the resolver instead of using a fixed issuer from the original module, matching the Vite adapter's behavior for recursive forward resolution. - HOOK_IMPORT_HINT regex now matches unstable_use* imports by allowing the optional unstable_ prefix, consistent with isHookName. - markEmptyDepsStable now uses analysis.trustedHookNames to verify the callee is a real Octane hook import rather than trusting the raw callee spelling, closing the soundness hole for shadowed names and restoring alias support.
1 parent 00adf44 commit 5462a7f

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎packages/octane/src/compiler/module-facts.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const STABLE_TUPLE_SLOTS = new Map([
5959

6060
const MAX_DEPTH = 4;
6161

62-
const HOOK_IMPORT_HINT = /\bimport\b[^;]*\buse[A-Z]/;
62+
const HOOK_IMPORT_HINT = /\bimport\b[^;]*\b(?:unstable_)?use[A-Z]/;
6363

6464
function unwrap(node) {
6565
while (
@@ -192,8 +192,8 @@ function markEmptyDepsStable(ast, analysis) {
192192
if (kind !== 'const' || decl.id.type !== 'Identifier') continue;
193193
const init = unwrap(decl.init);
194194
if (init?.type !== 'CallExpression') continue;
195-
const callee = unwrap(init.callee);
196-
if (callee?.type !== 'Identifier' || !EMPTY_DEPS_STABLE_HOOKS.has(callee.name)) continue;
195+
const trustedName = analysis.trustedHookNames.get(init) ?? null;
196+
if (trustedName === null || !EMPTY_DEPS_STABLE_HOOKS.has(trustedName)) continue;
197197
const deps = unwrap(init.arguments?.[1]);
198198
if (deps?.type !== 'ArrayExpression' || (deps.elements?.length ?? 0) !== 0) continue;
199199
const binding = bindings[0]?.binding;

‎packages/rspack-plugin-octane/src/loader.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ async function resolveClientOnlyImports(context, compiler, source, id) {
9292
*/
9393
function hookStabilityFor(context, candidates, id) {
9494
const resolver = context.getResolve({ dependencyType: 'esm' });
95-
const issuer = dirname(cleanModuleId(id));
9695
return resolveHookStability(candidates, id, {
97-
resolve: async (request) => {
96+
resolve: async (request, importer) => {
97+
const issuer = dirname(cleanModuleId(importer));
9898
let resolved;
9999
try {
100100
resolved = await resolver(issuer, request);
101101
} catch {
102102
return null;
103103
}
104-
return typeof resolved === 'string' && resolved !== cleanModuleId(id) ? resolved : null;
104+
return typeof resolved === 'string' && resolved !== cleanModuleId(importer) ? resolved : null;
105105
},
106106
readFile: async (path) => {
107107
try {

0 commit comments

Comments
 (0)