LearnNewsExamplesConnect
Frontmatter
assigneesneo-opus-grace
createdAtAug 30, 2026, 4:20 AM
updatedAtAug 30, 2026, 7:39 PM
githubUrlhttps://github.com/neomjs/neo/issues/17881
authorneo-opus-grace
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtAug 30, 2026, 7:39 PM

The data worker's webpackInclude is unanchored, so a workspace nested under an 'apps' ancestor bundles its whole tree

neo-opus-grace
neo-opus-grace commented on Aug 30, 2026, 4:20 AM

src/worker/Data.mjs#createInstance narrows its dynamic import with a webpackInclude magic comment:

let module = await import(
    /* webpackInclude: /(?:apps|docs\/app|examples|src\/data)\/.*\.mjs$/ */
    /* webpackExclude: /(?:\/|\\)(buildScripts|dist|node_modules(?:\/|\\)(?!neo\.mjs)|ai(?:\/|\\)|\.claude(?:\/|\\)|server\.mjs|test(?:\/|\\))/ */
    /* webpackMode: "lazy" */
    `../../${path}.mjs`
);

The context base is the repository root, and the include is what keeps that from meaning "every .mjs in the tree". It is unanchored, and webpack matches include/exclude against the absolute resource path — so any workspace with an ancestor directory named apps, examples, or docs/app matches on the ancestor, and the include stops narrowing anything.

The exclude on the very next line is separator-anchored ((?:\/|\\)(buildScripts|…)), so the anchoring question was clearly considered for one of the two and not the other.

Measured, with a control

Same engine version (13.1.0), same config, two dist/development/dataworker.js builds:

build context map entries entries matching the include relative to the root
this repo — no ancestor named apps 797 762 (95.6%)
a workspace nested under a parent directory named apps 1244 7 (0.6%)

In this repo the include works, because the apps/ it matches is the one at the context root. That is why the defect is invisible here and why it survived: the pattern is correct exactly when the repository is the thing being built.

In the nested workspace 1237 of 1244 registered modules match no relative form of the include. Files that reach the bundle include root-level Node-only scripts — a bootstrap.mjs and a devServer.mjs, each dragging a node_modules/url vendor chunk — and unrelated application trees such as client/src/**. A dev server is registered as a lazily-importable module inside a browser Web Worker.

Why it is worth fixing rather than tolerating

  • It is silent. The build succeeds, the app runs, and the only symptom is bundle size plus code that could never execute in a worker being reachable from one.
  • It is invisible to this repo's own builds, so no amount of testing here surfaces it.
  • The trigger is the consumer's directory name, not anything the consumer wrote. Nesting a workspace under apps/ is an ordinary layout choice, and nothing reports that it changed the build.

The shape of the fix

Filtering a too-wide context with a pattern is the fragile part; the pattern has to encode "relative to the context root" in a language that only sees absolute paths. Making the context base explicit avoids the class rather than tightening the regex — e.g. separate narrow imports per supported root (../../apps/…, ../../examples/…, ../../src/data/…) selected from the already-parsed path, so each context is rooted where it should be and an ancestor's name cannot widen it.

Tightening the include to require a separator ((?:\/|\\)(?:apps|…)) is not sufficient: an ancestor path still supplies the separator.

Contract Ledger Matrix

Backfilled 2026-08-30 at @neo-gpt's RA-3. The ticket originally prescribed one layer; the defect spans two, and the ledger has to say which layer owns what or the next change repeats the mistake.

Target Surface Source of Authority Behavior Fallback Docs Evidence
createInstance({config, path}) src/worker/Data.mjs consumed RMA method. Accepted roots: apps/, examples/, docs/app/, src/data/. A trailing .mjs suffix is stripped before dispatch, so apps/x/M and apps/x/M.mjs name the same module unsupported root throws, and is never resolved through a wider context method JSDoc unit suite; physical consumer build
loadModule({path}) src/worker/Data.mjs consumed RMA method; same four roots, same suffix rule, same refusal, via the shared helper as above method JSDoc as above
importAppSpaceModule(path) src/worker/Data.mjs one static-prefixed lazy context per root. Package-relative only — this layer never decides what apps/ means on disk typed refusal: Unsupported module root: <path> method JSDoc, which names the config-side half in-repo 930-chunk identity
workerContextRebasePlugin(insideNeo) buildScripts/webpack/workerContextRebasePlugin.mjs ownership boundary. App-space roots (apps, examples, docs/app) resolve to the consumer workspace; src/data stays package-local. An absent optional root keeps its package-relative request with an emptied match, so it contributes no modules and raises no resolution error insideNeo is a total no-op — the framework's own build is unaffected factory JSDoc 0 request mutations at insideNeo=true
development / dist parity both buildScripts/webpack/{development,production}/webpack.config.worker.mjs both modes install the same factory, so the mapping cannot differ between a dev build and a shipped one none — divergence is the defect this row exists to prevent workflow comment consumer fixture built in both modes

The invariant the two layers share: Data.mjs decides which roots exist; the worker configs decide where those roots live once the framework is a dependency. Changing the prefixes in one without the other breaks module resolution for every consumer, and the framework's own build cannot observe it.

Acceptance Criteria

  • The data worker's lazy context is rooted at the intended directories, so an ancestor directory named apps, examples, or docs/app cannot widen it.
  • A build produced from a workspace nested under such an ancestor registers only modules under the supported roots — proven by counting map entries against the intended set, since the build succeeds either way and the count is the only signal.
  • This repo's own build is unchanged: createInstance still resolves the same modules it does today.
  • Root-level Node-only scripts in a consuming workspace are not registered in a worker bundle.

Out of Scope

  • The identical webpackInclude/webpackExclude pairs elsewhere in src/worker/Data.mjs and src/worker/App.mjs — same class, but each needs its own before/after count rather than being swept along on the strength of this one.
tobiu closed this issue on Aug 30, 2026, 7:39 PM
tobiu referenced in commit df05ec3 - "fix(worker): root the Data Worker's lazy imports at explicit bases (#17882) on Aug 30, 2026, 7:39 PM