Skip to content

feat: routeTransforms option for non-TS route languages#2156

Open
STRd6 wants to merge 2 commits into
solidjs:mainfrom
STRd6:route-transforms
Open

feat: routeTransforms option for non-TS route languages#2156
STRd6 wants to merge 2 commits into
solidjs:mainfrom
STRd6:route-transforms

Conversation

@STRd6

@STRd6 STRd6 commented Jun 11, 2026

Copy link
Copy Markdown

Fixes #1549 (on main/v2; the vinxi-based 1.x line has the same issue — happy to backport, see notes below).

Problem

Route modules are analyzed for their exports by reading the file off disk and parsing it with esbuild's tsx loader (analyzeModule in fs-routes/router.ts, vendored from vinxi). Languages that compile to JS/TS — Civet, CoffeeScript, etc. — can't be parsed that way, so toRoute throws, addRoute swallows the error, and the route is silently dropped even though the user registered the extension via extensions and added a bundler plugin that handles the language everywhere else.

Reported here as #1549 and to Civet as DanielXMoore/Civet#1319. Civet currently works around it by monkey-patching toRoute and substituting fs.readFileSync during analysis (DanielXMoore/Civet#2148) — this PR is the seam that makes that workaround unnecessary.

Approach

A per-extension source transform that runs before export analysis, so all the existing pick/route-config/HTTP-method logic is reused and the transform author never sees es-module-lexer's shapes:

import civet from "@danielx/civet";

solidStart({
  extensions: ["civet"],
  routeTransforms: {
    civet: (code, sourcePath) => civet.compile(code, { filename: sourcePath, sync: true }),
  },
})
  • FileSystemRouterConfig gains routeTransforms?: Record<string, RouteModuleTransform> (extension without dot, matching how extensions is spelled), threaded through solidStart().
  • analyzeModule(src) is split into analyzeCode(code, sourcePath) plus a new analyzeRouteModule(sourcePath, config) that applies the matching transform first (and await inits the lexer, which watcher-triggered updates could otherwise race).
  • toRoute becomes async; its only callers (addRoute / updateRoute) were already async and now await it.

The hardcoded .md/.mdx carve-out in toRoute is untouched, but could conceivably migrate to this mechanism later.

Verification

tsc --noEmit on packages/start is clean. vitest run shows 2 failures that also fail for me on unmodified main (server-fns related), 5 passing.

Notes

  • Naming (routeTransforms, sourcePath) and shape are open to feedback — e.g. this could alternatively hang off extensions entries in a tuple form like vite-plugin-solid's extensions option.
  • The released 1.x line hits the same problem through vinxi's analyzeModule; since toRoute lives in this repo there too, a near-identical backport is possible without touching vinxi.

🤖 Generated with Claude Code

Route modules are analyzed for their exports with esbuild's tsx loader,
which fails on languages that compile to JS/TS (Civet, CoffeeScript,
...), silently dropping the route. Let bundler plugins/users register a
per-extension source transform that runs before analysis.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 103fb5e

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

This PR includes changesets to release 1 package
Name Type
@solidjs/start Minor

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

@netlify

netlify Bot commented Jun 11, 2026

Copy link
Copy Markdown

Deploy Preview for solid-start-landing-page ready!

Name Link
🔨 Latest commit 103fb5e
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/6a2ae4c9e8253400089fa3f8
😎 Deploy Preview https://deploy-preview-2156--solid-start-landing-page.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Jun 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/solidjs/solid-start/@solidjs/start@2156
npm i https://pkg.pr.new/solidjs/solid-start/@solidjs/vite-plugin-nitro-2@2156

commit: 103fb5e

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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?]: Page components - weird behaviour with transpiling plugins (@danielx/civet example)

1 participant