Skip to content

esm custom loader: multiple calls to nextHook within the same loader result in different nextHooks #43238

Closed
@JakobJingleheimer

Description

@JakobJingleheimer

Version

pre-release / nightly

Platform

macOS 12.3.1, M1

Subsystem

esm, loaders

What steps will reproduce the bug?

loader-a.mjs
export function resolve(specifier, context, nextHook) {
  assert(nextHook() === nextHook());
}

How often does it reproduce? Is there a required condition?

100%

A loader hook must call nextHook() more than once to reproduce.

What is the expected behavior?

nextHook should be the same within the same loader

What do you see instead?

The first nextHook is correctly the next in the chain; however, subsequent calls erroneously continue along the hook chain.

Additional information

Thanks @cspotcode for reporting.

Note that this requires loader chaining (#42623), which has not yet been released.

The problem is caused by ESMLoader::resolve() and ESMLoader::load() decrementing hookIndex every time next<HookName> is called. I believe this can be addressed by using a factory to produce the next<HookName> and decrementing the counter in there instead.

Metadata

Metadata

Labels

esmIssues and PRs related to the ECMAScript Modules implementation.loadersIssues and PRs related to ES module loaders

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions