Skip to content

fix(compiler): silence INVALID_ANNOTATION and SOURCEMAP_BROKEN warnings from workerPlugin#6718

Merged
johnjenkins merged 2 commits into
stenciljs:mainfrom
Scan0815:fix/worker-plugin-rollup-warnings
May 13, 2026
Merged

fix(compiler): silence INVALID_ANNOTATION and SOURCEMAP_BROKEN warnings from workerPlugin#6718
johnjenkins merged 2 commits into
stenciljs:mainfrom
Scan0815:fix/worker-plugin-rollup-warnings

Conversation

@Scan0815
Copy link
Copy Markdown
Contributor

@Scan0815 Scan0815 commented May 13, 2026

What is the current behavior?

Every project that bundles a *.worker.ts (or *.worker.tsx) entry emits two bundling warnings on every build:

[ WARN  ]  Bundling Warning INVALID_ANNOTATION
           src/<name>.worker.ts?worker (4:19): A comment "/*@__PURE__*/" in "src/<name>.worker.ts?worker"
           contains an annotation that Rollup cannot interpret due to the position of the comment.
           The comment will be removed to avoid issues.

[ WARN  ]  Bundling Warning SOURCEMAP_BROKEN
           [plugin workerPlugin] Sourcemap is likely to be incorrect: a plugin (workerPlugin) was used
           to transform files, but didn't generate a sourcemap for the transformation. Consult the
           plugin documentation for help.

The SOURCEMAP_BROKEN variant has been tracked as a validated bug for over three years (#3476, opened against v2.17.1, labels Bug: Validated, Help Wanted). A minimal reproduction repo is linked from that issue: https://github.com/Scan0815/stencil-source-map-error. Both warnings originate from src/compiler/bundle/worker-plugin.ts. There is no user-facing way to suppress them: validateRollupConfig (src/compiler/config/validate-rollup-config.ts) whitelists only context, moduleContext, treeshake, external, maxParallelFileOps from rollupConfig.inputOptions, so an onwarn override on stencil.config.ts is dropped before reaching Rollup. The hardcoded ignoreWarnCodes set in src/utils/logger/logger-rollup.ts does not include either code.

Fixes #3476

What is the new behavior?

Two independent fixes in src/compiler/bundle/worker-plugin.ts:

1. INVALID_ANNOTATION/*@__PURE__*/ is meaningful only in front of call or new expressions. In getWorkerMain and getInlineWorker the marker was placed in front of import.meta.ROLLUP_FILE_URL_*, a property access. Rollup cannot apply pure-side-effect analysis there and strips the comment with the warning above. The two stale markers on workerPath are removed. The remaining /*@__PURE__*/ markers on the actual createWorker(...) / createWorkerProxy(...) calls are unchanged and still effective.

2. SOURCEMAP_BROKEN (#3476) — the transform hook returned synthetic wrapper code without a sourcemap. The Rollup plugin convention for transforms that produce code with no useful source-position mapping is to return map: { mappings: '' }. All five transform return paths now do so: the mocked hydrate/worker-platform branch and the four real-bundle branches (?worker, ?worker-inline, proxy + inline-proxy).

Neither change alters runtime behavior. The two commits are kept separate so each fix is independently revertable.

Documentation

N/A — no public API surface change.

Does this introduce a breaking change?

  • Yes
  • No

Testing

  • npx tsc --noEmit passes after each commit.
  • ESLint reports no new errors on src/compiler/bundle/worker-plugin.ts (a pre-existing simple-import-sort/imports finding on main is left untouched to keep this PR focused).
  • Full project build (npm run build) and end-to-end verification against the bug: Bundling Warning SOURCEMAP_BROKEN if web-worker is used #3476 reproduction repo have not been performed locally and are deferred to CI / reviewer verification. Steps to reproduce remain those in the original issue.
  • No new unit tests added: the touched helpers are non-exported template-string builders and the bundling transforms return synthetic wrapper code; both fixes are warning-suppressing only and have no behavioral surface that a Jest spec could meaningfully assert beyond duplicating the snippet. Happy to add a targeted spec if reviewers prefer.

Other information

The two affected helpers (getWorkerMain, getInlineWorker) and the four transform return branches were unchanged in behavior across recent history, so this is purely a hygiene fix on long-standing output. Disclosure: I'm the original reporter of #3476.

oliver added 2 commits May 13, 2026 15:15
The /*@__PURE__*/ annotation is only meaningful in front of call or
new expressions. In getWorkerMain and getInlineWorker it was placed
before an import.meta.ROLLUP_FILE_URL_* property access, which Rollup
cannot interpret and silently strips with an INVALID_ANNOTATION warning
on every build of a project that uses *.worker.ts entries.

Drop the unused annotation on the workerPath assignment. The remaining
PURE markers on the createWorker(...) / createWorkerProxy(...) calls
are unchanged.
The workerPlugin transform hook returned synthetic wrapper code without
a sourcemap, triggering a SOURCEMAP_BROKEN warning from Rollup for every
project that builds a *.worker.ts entry. The Rollup plugin convention
for transforms that produce code with no useful source-position mapping
is to return an empty mappings string; do that for all five transform
return paths (the mocked hydrate/worker-platform branch and the four
real-bundle branches).
Copilot AI review requested due to automatic review settings May 13, 2026 13:18
@Scan0815 Scan0815 requested a review from a team as a code owner May 13, 2026 13:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses persistent Rollup bundling warnings emitted whenever a project bundles *.worker.ts / *.worker.tsx entries, by fixing the warning sources inside the internal workerPlugin implementation.

Changes:

  • Remove invalid /*@__PURE__*/ annotations that were placed on import.meta.ROLLUP_FILE_URL_* property access, which triggers Rollup’s INVALID_ANNOTATION warning.
  • Return an explicit empty sourcemap (map: { mappings: '' }) from all transform paths that generate synthetic wrapper modules, silencing SOURCEMAP_BROKEN.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@johnjenkins johnjenkins left a comment

Choose a reason for hiding this comment

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

LGTM

@johnjenkins johnjenkins added this pull request to the merge queue May 13, 2026
Merged via the queue into stenciljs:main with commit ef79a49 May 13, 2026
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Bundling Warning SOURCEMAP_BROKEN if web-worker is used

3 participants