refactor: give the client a textUtils mirror so escapeRegExp stops being re-inlined (#5790) - #5986
Merged
Conversation
…ing re-inlined (#5790) The browser cannot import `server/lib/textUtils.js`, so the client had no home for the RegExp escape and every new caller pasted the character class again — six private copies across `lib/`, `components/`, `pages/` and a hook test. That gap also forced a documented hole in the server-side guard: `server/lib/ scenePrompt.js` is held in sync with its client mirror, so it could not migrate to `escapeRegExp` while the client had no such call to mirror. Adds `client/src/lib/textUtils.js` as the declared client mirror (the `escapeRegExp` half only — `countWords` already mirrors via `utils/formatters.js` and nothing on this side calls `trimTo`/`kebabCase`), registers it in the barrel and catalog, and pins it against the server copy with a parity test. Every client copy now imports it, including both sides of `scenePrompt.js`, which retires the guard's single exemption. The guard itself now scans `client/src/` too, via a new `collectClientSources` beside `collectServerSources`. That walk counts `.jsx` (two of the copies lived in components) and does NOT skip tests (one lived in a client test), so a re-inlined copy fails the suite on either side of the mirror. Claude-Session: https://claude.ai/code/session_01Uz59AsJawa1Djqm2T9Fb8t
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The browser cannot import
server/lib/textUtils.js, so the client had no home for the RegExp escape — and every new caller pasted the character class again. Six private copies had accumulated acrossclient/src/lib/,client/src/components/,client/src/pages/and a hook test.That gap also forced the documented hole in the server-side guard:
server/lib/scenePrompt.jsis held in sync with its client mirror, so it could not migrate toescapeRegExpwhile the client had no equivalent call to mirror. It was the guard's single exemption.client/src/lib/textUtils.js— the declared client mirror ofserver/lib/textUtils.js. Partial on purpose: onlyescapeRegExpcrosses, sincecountWordsalready mirrors throughclient/src/utils/formatters.jsand nothing on this side callstrimTo/kebabCase. Registered inclient/src/lib/index.jsand theREADME.mdcatalog, and pinned against the server copy by acompareDeclarationparity test inserver/lib/textUtils.test.js(which is whatmirrorCoverage.test.jsrequires of a declared mirror).lib/loraTriggers.js,lib/editorialChecks.js,lib/manuscriptAnchors.js,lib/scenePrompt.js,components/CmdKSearch.jsx,pages/LoraDatasetDetail.jsx(2 sites),hooks/mountedRefConventions.test.js.server/lib/scenePrompt.jsmigrated too, in the same change so the two mirrored declarations stay in sync — which retires theHOLDOUTexemption from the guard entirely.client/src/as well, via a newcollectClientSources/readClientSourcepair besidecollectServerSourcesinserver/lib/testHelper.js. Two deliberate differences from the server walk, documented at the helper: it counts.jsx(two copies lived in components, so a.js-only walk would report a clean tree) and it does NOT skip*.test.js(one copy lived in a client test; the server walk skips tests only because the guard file itself lives there and spells the idiom).Test plan
cd client && npm test— 824 files / 10093 tests pass.cd server && npm test— 1888 files / 38071 tests pass, including thescenePromptmirror-parity suite andmirrorCoverage.client/src/lib/uuid.jsfails the new client-side guard withexpected [ 'lib/uuid.js' ] to deeply equal []; reverted. The server-side half was already proven by the existing suite.grepconfirms the escape character class now appears in exactly two source files repo-wide:server/lib/textUtils.jsandclient/src/lib/textUtils.js.Closes #5790
https://claude.ai/code/session_01Uz59AsJawa1Djqm2T9Fb8t