3 Commits

Author SHA1 Message Date
Nathan Nguyen 0b63ad5237 perf: pre-split route patterns and hoist URL split out of match loop (#396)
* perf: pre-split route patterns and hoist URL split out of match loop

Route matching runs on every request and iterates all routes until a
match is found. Previously, matchPattern() re-split both the URL and
the pattern string on every iteration:

  for (const route of routes) {
    // url.split("/") — same URL, re-split every iteration
    // pattern.split("/") — pattern never pre-computed
    matchPattern(normalizedUrl, route.pattern);
  }

For a 50-route app on a 404, that's 50 URL splits + 50 pattern splits
+ 50 Object.create(null) + 100 .filter(Boolean) calls.

Fix:
- Add `patternParts: string[]` to Route and AppRoute interfaces,
  computed once at scan time
- Split the URL once in matchRoute/matchAppRoute before the loop
- Pass pre-split arrays to matchPattern instead of raw strings
- Apply the same optimization to generated production entries
  (pages-server-entry.ts, app-rsc-entry.ts)
- Fix intercepting route lookup to use the new array-based API

* update entry-templates snapshots

---------

Co-authored-by: James <james@eli.cx>
2026-03-10 08:18:30 +00:00
James Anderson 764a496ce7 add oxfmt formatter (#380)
* add oxfmt formatter: config, scripts, CI, editor setup, docs

* rebuild lockfile

* fix: add Format to required checks list, remove dead ignore pattern

* run fmt

* add format to agents.md again
2026-03-09 14:56:14 +00:00
Nathan Nguyen c1ceef2aaf test: add unit tests for Pages Router api-handler (#318)
Cover body parsing (JSON, form-urlencoded, plain text, empty, malformed),
cookie parsing (single, multiple, values with =, missing header),
req/res extensions (status chaining, json, send for objects/strings/numbers/null,
redirect with default 307 and custom status codes), query string and dynamic
param merging (including array promotion for duplicate keys), MAX_BODY_SIZE
enforcement (413 for >1 MB), and error handling (missing default export,
non-function export, handler throws, ssrFixStacktrace integration).
2026-03-07 17:11:56 +00:00