Skip to content

Older Safari (before 16.4): Admin, most pages and Markdown replies draw again - #2930

Merged
davidmckayv merged 1 commit into
mainfrom
fix/no-regex-lookbehind
Dec 4, 2026
Merged

davidmckayv merged 1 commit into
mainfrom
fix/no-regex-lookbehind

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

What this changes

In Safari 16.0 to 16.3, and in OpenBot Desktop on a Mac older than macOS 13.3 (its window draws with the Mac's own Safari), every Admin page and most of the app's pages showed "This page couldn't be shown". Every reply in Markdown and every document failed to draw as well. Chat's shell still loaded.

Cause. Regular expressions with a lookbehind ((?<= or (?<!). WebKit reads them only from Safari 16.4. The app is built for Safari 16.0 (Vite's default), so the build turns each such literal into new RegExp("…"). The chunk still parses, and the error comes when the code runs: SyntaxError: Invalid regular expression: invalid group specifier name. Desktop shows the same error as ReferenceError: Cannot access uninitialized variable (WebKit bug 190843). The one that broke Admin is in the tool words (BY_ITS_ID), which compiled as its chunk loaded. It has been there since v0.3.4.

Every lookbehind the build ships, now without one, with the same output:

  • lib/plugins/tool-words.ts:
    • The first clause of a tool description.
    • BY_ITS_ID ("sorted by ID" is not "by its ID"). It now finds the match first and checks the word before "by". A refused match resumes one character on, the way the engine moves past a refused lookbehind.
  • lib/maths.ts:
    • Escaping a $ inside a formula.
    • Cutting a reply into lines.
  • lib/tasks/line.ts:
    • Cutting a table row at unescaped |.
    • Removing closing underscores.
  • components/audit/audit-cells.tsx: the break points in an identifier.
  • lib/boundaries/rules.ts: a rule's sentences. This one wasn't in the triage; the bundle scan found it.
  • mdast-util-gfm-autolink-literal (through remark-gfm, under Streamdown). Its email finder /(?<=^|\s|\p{P}|\p{S})…/gu runs on every Markdown parse.
    • Upstream's newer releases (2.1.x) add more lookbehinds, not fewer.
    • A small build plugin replaces the finder, the same way the build already rewrites Zod's settings. The replacement is src/lib/markdown-email-links.ts, a RegExp whose exec returns the same match from any lastIndex.
    • Simply deleting the lookbehind would find the same addresses. But it tries every position in a long word, which made an 80,000-character word take 2.4 s. The replacement only tries where the lookbehind would, so it stays fast.

Nothing else in the build uses a newer regular-expression feature. No other app code does either: no v flag, no group name used twice, no modifiers. Under desktop/src, lookbehinds appear only in tests. marked compiles one inside a try as a feature test and falls back, so it stays.

Also changed:

  • app/vite.config.ts now sets build.target explicitly, to Vite's own default: Chrome and Edge 107, Firefox 104, Safari 16. The floor stays where it was, but it is now written down.
  • New dev dependencies acorn 8.19.0 and @eslint-community/regexpp 4.12.3, both used only by the test.

How the leaders guard this, and what this does. Two kinds of check are in common use:

  • Source linting. eslint-plugin-es-x's no-regexp-lookbehind-assertions (docs), often run through browserslist presets. It reads only our own source, so it would miss the mdast lookbehind. This repo also lints with Biome, not ESLint.
  • Checking the built bundle. es-check (v9, --checkBrowser with browserslist) and Rsbuild's check-syntax. es-check says outright that "strings passed to the RegExp constructor are not parsed as regular expression source". The build turns every lookbehind into exactly that, so it would miss all nine.

So this follows the bundle-checking approach, built from the same widely used parts. The test parses every built chunk with acorn and reads each regex literal and each RegExp("…") with @eslint-community/regexpp, the parser ESLint itself uses. It fails on anything Safari 16.0 can't compile.

Where it runs

In the browser only. No server state, no new listener.

  • New state that outlives a request? None.
  • What happens on the second replica? Nothing changes; this is browser code.
  • Anything serialised? No.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No.

Boundary and audit

  • Every acting call still goes through the gateway: unchanged.
  • New refusals and new failures each write a row: none added.
  • Nothing new is trusted from the client.

API and database

  • This changes nothing under api/, no app's requests, no database change and no release-policy.json.

Changelog

Fixed.

  • Fixed: Admin, most pages, and replies in Markdown draw again in Safari 16.0 to 16.3 and in OpenBot Desktop on older macOS. They showed "This page couldn't be shown", because those versions of Safari can't read part of the app's text handling. The app now works in every browser it is built for, from Safari 16.0, Chrome 107 and Firefox 104 up.

Proof

app/tests/older-safari-build.test.ts builds the app as it ships. A run on main fails 7 of 7 tests; this branch passes 7 of 7. It checks:

  • The bundle scan. On main it lists the nine regular expressions above, with their chunks. On this branch it lists none.
  • The pages, in Chromium and WebKit. Each page loads with Safari 16.0's regex rules in place: the RegExp constructor refuses a lookbehind with WebKit's own message before any page code runs. The pages are an Admin page (People), an app page (Apps), and a public document containing an email address and two formulas.
    • On main: People and Apps show "This page couldn't be shown" with the SyntaxError. The document shows "This artifact couldn't be shown".
    • On this branch: all three draw, with no error. The email is a mailto: link and both formulas are KaTeX.

app/tests/older-safari-same-words.test.ts holds each rewrite to the lookbehind it replaces, on a current engine.

  • Inputs: real tool descriptions, rules, task lines, formulas and addresses, then the cases at each lookbehind's edge ("sorted by ID", "unsorted by ID", \$, \|, a__b, astral characters before an address), then a few thousand seeded strings per rule.
  • About 26,000 comparisons, all identical.
  • The email finder is compared from every lastIndex, which is how mdast-util-find-and-replace calls it.
  • The existing tests for tool words, maths, task lines, boundaries and audit pass unchanged.

No visual change. The main build and this build were screenshotted in WebKit and Chromium, light and dark, on Admin People, Admin Activity (identifier breaks), Apps and the document, with no shim and the same API answers. All 16 pairs are pixel-identical.

Checks run:

  • Biome lint and format.
  • tsc for the app and the workbench.
  • scripts/ci-changes.test.ts.
  • The new file is added to the WebKit job's list in ci.yml, next to trusted-types-build.

Safari 16.0 to 16.3, and OpenBot Desktop on macOS before 13.3, can't read
a regular expression lookbehind. The build targets Safari 16.0 and turns
each one into new RegExp("..."), so it threw when its chunk ran: every
Admin page and most app pages showed "This page couldn't be shown", and
every Markdown reply and document failed to draw.

Rewrite the eight lookbehinds in the app without one, with the same
output, and replace GitHub-flavoured Markdown's email finder in the build
with one that finds the same matches as quickly. Set build.target to the
Safari 16.0 floor explicitly. A test reads every regular expression in
the built chunks and fails on anything Safari 16.0 can't compile, and
loads Admin, Apps and a document under Safari 16.0's regex rules in
Chromium and WebKit.
@davidmckayv
davidmckayv added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit bb610dc Dec 4, 2026
39 checks passed
@davidmckayv
davidmckayv deleted the fix/no-regex-lookbehind branch December 4, 2026 11:12
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