Repository navigation
fix(core): build Unicode property regexes at runtime - #7767
Conversation
With no browserslist, or targets without Unicode property escapes,
next/babel's preset-env rewrites every `\p{…}` regex literal through the
transform bundled in Next.js, which lacks the Unicode data it loads, so a
source build of the documented Next.js setup failed with
"Unknown property: L" in Avatar, the Markdown parser and heading links.
Build those four expressions with `new RegExp(...)`, as numberParser.ts
already does, and add a source-build test that fails when a Core module
writes a property escape as a regex literal.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsMarkdown (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression40 of 486 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 20 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Recommended for approval. The four Unicode property-escape expressions keep their exact source and flags, so initials, emphasis and heading IDs are unchanged, and compiling Core with Next 16.3.6's bundled Babel and no browserslist goes from three failing modules (Avatar.tsx, Markdown/parser.ts, Markdown/plugins/headingLinks.ts) to none. The new guard test fails on main at exactly those four literals and passes here, and the [fix] patch changeset is valid, so nothing further is needed from you.
[Automated review]
…ibrary pass (#7774) <!-- template: bug-fix.md --> ## User impact Every documented Next.js source build pays for an unused Babel run over every installed Astryx module. `@astryxdesign/build`'s PostCSS plugin compiles Astryx source to collect its StyleX rules with `babelrc: false` but not `configFile: false`, so Babel also loads the app's root `babel.config.js`: in the documented setup, `next/babel` plus Astryx's StyleX plugin. The CSS pass then runs preset-env, Next's plugins and a second StyleX instance over package source, only to read StyleX metadata. On a clean install of the documented example that roughly doubles the pass, for byte-identical CSS. ## Problem and solution fit - Why it happens: `babelrc: false` only disables `.babelrc` files; Babel still loads a root config file unless told `configFile: false`. - Why it harms: the extra transforms produce nothing the pass uses, and they scale with the Astryx packages installed, not used. - Why that matters: the app cannot keep its root config out of the plugin's pass without dropping it from its own compile. ## Expected behavior and authority No record governs the plugin's build cost. `spec:AST-080` FR7 (current) governs its output, which stays byte-identical. The pass already opts out of the app's Babel configuration with `babelrc: false` (since #1421); `configFile: false` extends that to the root config file Babel also loads. #5464 shows the same leak failing a consumer's StyleX pass. ## Smallest restoration - The library pass sets `configFile: false`; it already passes its own parser options and plugins. - The app's own files still compile with its config, which may carry syntax plugins they need. ## Evidence - Reproduction before the change: on a clean registry install of the documented example, the app's PostCSS config takes a median 37.4 s with the README's browserslist and 67.3 s with none (5 fresh-process runs each, alternating order; the no-browserslist case has #7767 applied, since main does not build without one). - Result after the change: 20.3 s and 21.4 s, with byte-identical CSS across all 20 runs. - Representative unchanged path: the app's own files still compile with its config, which the test asserts. - Regression test or other mutation-sensitive proof: `postcss.test.mjs` runs the documented config from an app whose `babel.config.js` records each file it is applied to. On main it records the Astryx module; here only the app's. ## Scope - [x] One defect is restored. - [x] Separable contradictory or unsettled tagalongs were removed or split. - [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. - [x] Public text and artifacts contain no internal Meta context. ## Testing - `pnpm exec vitest run --project node packages/build`: 6 files, 79 tests pass; `postcss.test.mjs` fails on main. - CSS-pass runs, before and after: README browserslist 35.7/41.1/36.7/37.4/38.1 s and 19.9/24.8/20.3/20.0/22.8 s; none 67.3/75.8/67.8/65.9/52.9 s and 19.9/21.4/24.9/24.7/19.7 s. - `pnpm -F @astryxdesign/core typecheck`, Prettier, `pnpm check:repo`, changeset coverage: pass (ESLint ignores `packages/build/src`).
User impact
An app that builds Astryx from source with the documented Next.js setup, but sets no browserslist or targets a browser without Unicode property escapes (such as Safari 11), fails
next build --webpackwithUnknown property: L(alsoZs,Letter). The errors point atAvatar.tsx,Markdown/parser.tsandMarkdown/plugins/headingLinks.ts, package source the app cannot change, and come from both the PostCSS pass and the JavaScript compile. Any import from the package root reaches them.Problem and solution fit
next/babel's preset-env rewrites every\p{…}regex literal with transform-unicode-property-regex. Next's bundled copy of that transform loadsregenerate-unicode-propertiesat runtime, which Next does not ship, so it throws (Next 16.3.6 and 16.4.2 alike).Expected behavior and authority
This is a regression of a settled case. #5450 hit this failure in
NumberInput/numberParser.tsand builds those expressions withnew RegExp(...); its comment records why, and notes that property escapes need no transform in any browser this package supports. #6698, #6911 and #7051 later added four new literals and reintroduced it.Smallest restoration
new RegExp(...)with the same pattern and flags, built once at module load as before.Evidence
apps/example-nextjs-source, hoisted, browserslist removed).next build --webpackfails in the PostCSS pass (Avatar.tsx: Unknown property: L) and in the JavaScript compile (Unknown property: L,Zs,Letterfrom the three files).unicodePropertyEscapes.source-build.test.mjsfails on main listing the four literals, and passes here.Scope
Testing
pnpm exec vitest run --project ui packages/core/src/Avatar packages/core/src/Markdown packages/core/src/unicodePropertyEscapes.source-build.test.mjs: 50 files, 1,158 tests pass (the new test alone fails on main).next build --webpackon the clean install, no browserslist: fails on main in both passes; passes with this change (226 of 226 rendered classes have a rule).pnpm -F @astryxdesign/core typecheck, ESLint and Prettier on the touched files,pnpm check:repo, changeset coverage: pass.