Skip to content

fix(core): preserve query in bundleless redirects - #1707

Draft
Timeless0911 wants to merge 1 commit into
mainfrom
david/fix-bundleless-query-redirect
Draft

fix(core): preserve query in bundleless redirects#1707
Timeless0911 wants to merge 1 commit into
mainfrom
david/fix-bundleless-query-redirect

Conversation

@Timeless0911

Copy link
Copy Markdown
Contributor

Summary

This PR fixes bundleless redirect handling for JS and style imports with query strings. JS/TS redirects now preserve query and fragment parts while rewriting extensions, plain CSS keeps query strings when redirecting to emitted CSS files, and CSS Modules with query strings redirect to the emitted CSS asset instead of putting the query on the JS wrapper. Asset and SVGR query semantics are intentionally left out of this PR for a separate bundleless asset output design.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Timeless0911 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Current issue and scope of this PR

The core issue is that bundleless redirect only rewrites import specifiers, while artifact generation is handled separately. Simply preserving a query does not mean that the semantics of ?raw, ?inline, or ?react have actually been implemented.

This draft PR is currently scoped as follows:

Type Current behavior
JavaScript Preserve the query/fragment while rewriting the extension as usual, e.g. foo.ts?xfoo.js?x
Plain CSS Preserve the query and redirect to the extracted CSS file, e.g. index.less?inlineindex.css?inline
CSS Modules Without a query, continue redirecting to the JS wrapper; with a query, redirect to the extracted CSS file, e.g. index.module.less?inlineindex_module.css?inline
Regular assets such as PNG Keep the existing behavior and leave query support out of this PR
SVGR Leave it out of this PR to avoid preserving a query on an unsupported query import when no corresponding wrapper is emitted

The CSS Modules handling covers different preprocessors rather than only .module.css:

index.module.less  -> index_module.css
index.module.scss  -> index_module.css
index.module.styl  -> index_module.css

Regular assets cannot use the same path-preservation logic directly because bundleless asset handling currently looks roughly like this:

source PNG
  -> emit into static
  -> generate an intermediate JS wrapper
  -> application code imports the JS wrapper

For example, redirect could preserve this import:

import raw from './logo.png?raw';

However, if the build only emits a JS wrapper or static/logo.png, there is no artifact corresponding to the preserved ./logo.png?raw specifier. SVGR imports such as ?react and ?url have the same underlying issue, with the additional question of whether they should emit a React wrapper, a URL wrapper, or externalize/copy the original file.

Therefore, this PR only fixes cases where JS, CSS, and CSS Modules already have a well-defined output artifact and redirect was dropping the query. Asset and SVGR support should be designed separately together with asset externalization/copying and proxy-module generation. Bundle mode continues to rely on bundler/loader query handling; this change is focused on bundleless redirect behavior and is not intended to change bundle-mode semantics.

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