Skip to content

fix: compile templates whose id carries an unknown query - #299

Merged
DylanPiercey merged 2 commits into
mainfrom
dpiercey-ws-marko-pnpm-triage-ulgto5
Jul 24, 2026
Merged

fix: compile templates whose id carries an unknown query#299
DylanPiercey merged 2 commits into
mainfrom
dpiercey-ws-marko-pnpm-triage-ulgto5

Conversation

@DylanPiercey

Copy link
Copy Markdown
Contributor

stripViteQueries stripped an allowlist of three params (cache, v, t), so any other query left the id failing isMarkoFile and the template flowed through load/transform uncompiled. @vitest/coverage-istanbul re-requests uncovered files as foo.marko?cache=…&vitest-uncovered-coverage=true, so raw Marko source reached its babel instrumenter and vitest run --coverage died with a SyntaxError on any .marko file no test imported.

Splits the two things that function conflated: cleanUrl answers "what file is this" (and no longer emits the malformed ?&… ids the old strip left behind), hasOpaqueQuery answers "may Marko compile it" for the vite queries that change what the module is. load and transform bail on the latter, which is what keeps ?raw and ?url working — they previously worked only as a side effect of the id failing the .marko check.

Note this inverts a denylist into an allowlist: an unknown content-changing query from a third-party plugin would now be compiled rather than skipped. That looks like the right default (cache-busters and markers vastly outnumber them, and vite's set is stable), but it's a judgement call worth a second opinion.

Verified against a real vitest 4.1.10 + @vitest/coverage-istanbul project with an un-imported .marko: crashes before, passes after with the file reporting real coverage numbers. Covered here by unit cases on the id helpers plus dev-server tests that a marker-queried request transforms identically to the plain one while ?raw/?url still return source text and url.

`stripViteQueries` only stripped `cache`, `v` and `t`, so any other query
left the id failing `isMarkoFile` and the template was handed to the rest of
the pipeline uncompiled — `@vitest/coverage-istanbul` re-requests uncovered
files with its own marker and the raw Marko source reached babel.

Split identity from the compile gate: `cleanUrl` for "what file is this",
`hasOpaqueQuery` for the vite queries that change what the module is, which
`load`/`transform` now bail on so `?raw` and `?url` keep working.
@changeset-bot

changeset-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 09aef2d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@marko/vite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4a562807-45bd-411e-9d69-9654f00aea9a

📥 Commits

Reviewing files that changed from the base of the PR and between 472ee29 and 09aef2d.

📒 Files selected for processing (5)
  • .changeset/compile-templates-with-unknown-queries.md
  • agent-feedback/dx.md
  • src/__tests__/query.test.ts
  • src/index.ts
  • src/query.ts

Walkthrough

Adds query utilities that separate transparent URL markers from opaque payload-changing queries. Updates Marko plugin resolution, side-effect tracking, loading, and transformation to normalize transparent query IDs while deferring opaque queries to Vite. Adds unit and Vite integration tests covering unknown marker, cache-busting, raw, and url queries. Documents the patch release and a dev-server shutdown workaround for the test setup.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: compiling templates with unknown query-bearing IDs.
Description check ✅ Passed The description is directly about the query-handling fix and test coverage, matching the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dpiercey-ws-marko-pnpm-triage-ulgto5

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Comment @coderabbitai help to get the list of available commands.

Vite's dev cjs interop consts are hoisted in a nondeterministic order, so
asserting the whole transform result matched the un-queried request failed on
windows while passing on linux.
@DylanPiercey
DylanPiercey merged commit 558ece5 into main Jul 24, 2026
7 checks passed
@DylanPiercey
DylanPiercey deleted the dpiercey-ws-marko-pnpm-triage-ulgto5 branch July 24, 2026 20:26
@github-actions github-actions Bot mentioned this pull request Jul 24, 2026
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.

1 participant