Repository navigation
fix(compat): load on Safari and iOS 16.2 - #1019
Merged
Merged
Conversation
Safari parses RegExp lookbehind only from 16.4, and a regex literal it cannot parse is a SyntaxError for the whole script chunk. `/` renders on the client, and lib/markdown.ts sits in its first-load page chunk, so its two lookbehind literals were enough to leave iOS 16.2 on a blank page. Emulate the leading lookbehinds instead: try a sticky pattern at each opener in turn and skip one that follows an excluded character, which is the order in which the lookbehind version tries start positions. The lookbehind before the closing delimiter becomes the last character class of the content. Tests compare both rewrites with the old lookbehind regexes on 20k generated lines each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Next 16 compiles for Safari 16.4+ by default, so SWC leaves class
`static {}` blocks alone. Next's own App Router error boundary has one,
and Safari 16.2 rejects the App Router runtime chunk with "Unexpected
token '{'". A browserslist that lowers safari and ios_saf to 16.2 makes
SWC compile it to a private static field and keeps Next's other
defaults. Other node_modules keep the syntax they ship, so mermaid and
@mermaid-js/parser, whose lazy diagram chunks hold ~270 static blocks,
are added to transpilePackages; otherwise diagrams would still fail on
16.2.
SWC cannot downlevel a lookbehind, and remark-gfm's
[email protected] ships one in its email regex, also
in the first-load chunk; upstream declined to change it. A small loader
builds that regex at runtime and falls back to the 2.0.0 regex where
lookbehind is missing. Both find the same emails: findEmail already
rejects every start the lookbehind skips, and findAndReplace retries a
rejected match one character later. The fallback is only slower on long
runs of word characters, and only on those old browsers. The loader is
registered for webpack (`npm run build`) and Turbopack (`next dev`):
Next 16 exits `next dev` when a `webpack` hook has no `turbopack` config.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Kano-u
pushed a commit
to Kano-u/pi-web
that referenced
this pull request
Oct 2, 2026
解开 agegr#981 的 DirectoryPicker 冲突后,这一段(390e70f..f52fd84)实测 0 冲突: - agegr#992 移动端输入框停在键盘上方并给打字更多空间 - agegr#997 限制每客户端 SSE 积压 - agegr#1001 可配置发送键(Enter / Ctrl+Enter) - agegr#1006 从 pi 的 provider catalog 解析 discovery endpoint - agegr#1017 空闲关闭被禁用时回收 Stop 无法解除的运行 - agegr#1016 Stop 结束输出被幸存进程持住的命令 - agegr#1015 保留用户消息里输入的换行 - agegr#1019 在 Safari / iOS 16.2 上可加载(新增 browserslist,无新依赖)
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 6, 2026
* fix(compat): drop RegExp lookbehind from markdown helpers (agegr#753) Safari parses RegExp lookbehind only from 16.4, and a regex literal it cannot parse is a SyntaxError for the whole script chunk. `/` renders on the client, and lib/markdown.ts sits in its first-load page chunk, so its two lookbehind literals were enough to leave iOS 16.2 on a blank page. Emulate the leading lookbehinds instead: try a sticky pattern at each opener in turn and skip one that follows an excluded character, which is the order in which the lookbehind version tries start positions. The lookbehind before the closing delimiter becomes the last character class of the content. Tests compare both rewrites with the old lookbehind regexes on 20k generated lines each. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compat): compile the client for Safari and iOS 16.2 (agegr#753) Next 16 compiles for Safari 16.4+ by default, so SWC leaves class `static {}` blocks alone. Next's own App Router error boundary has one, and Safari 16.2 rejects the App Router runtime chunk with "Unexpected token '{'". A browserslist that lowers safari and ios_saf to 16.2 makes SWC compile it to a private static field and keeps Next's other defaults. Other node_modules keep the syntax they ship, so mermaid and @mermaid-js/parser, whose lazy diagram chunks hold ~270 static blocks, are added to transpilePackages; otherwise diagrams would still fail on 16.2. SWC cannot downlevel a lookbehind, and remark-gfm's [email protected] ships one in its email regex, also in the first-load chunk; upstream declined to change it. A small loader builds that regex at runtime and falls back to the 2.0.0 regex where lookbehind is missing. Both find the same emails: findEmail already rejects every start the lookbehind skips, and findAndReplace retries a rejected match one character later. The fallback is only slower on long runs of word characters, and only on those old browsers. The loader is registered for webpack (`npm run build`) and Turbopack (`next dev`): Next 16 exits `next dev` when a `webpack` hook has no `turbopack` config. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 8, 2026
* fix(compat): drop RegExp lookbehind from markdown helpers (agegr#753) Safari parses RegExp lookbehind only from 16.4, and a regex literal it cannot parse is a SyntaxError for the whole script chunk. `/` renders on the client, and lib/markdown.ts sits in its first-load page chunk, so its two lookbehind literals were enough to leave iOS 16.2 on a blank page. Emulate the leading lookbehinds instead: try a sticky pattern at each opener in turn and skip one that follows an excluded character, which is the order in which the lookbehind version tries start positions. The lookbehind before the closing delimiter becomes the last character class of the content. Tests compare both rewrites with the old lookbehind regexes on 20k generated lines each. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(compat): compile the client for Safari and iOS 16.2 (agegr#753) Next 16 compiles for Safari 16.4+ by default, so SWC leaves class `static {}` blocks alone. Next's own App Router error boundary has one, and Safari 16.2 rejects the App Router runtime chunk with "Unexpected token '{'". A browserslist that lowers safari and ios_saf to 16.2 makes SWC compile it to a private static field and keeps Next's other defaults. Other node_modules keep the syntax they ship, so mermaid and @mermaid-js/parser, whose lazy diagram chunks hold ~270 static blocks, are added to transpilePackages; otherwise diagrams would still fail on 16.2. SWC cannot downlevel a lookbehind, and remark-gfm's [email protected] ships one in its email regex, also in the first-load chunk; upstream declined to change it. A small loader builds that regex at runtime and falls back to the 2.0.0 regex where lookbehind is missing. Both find the same emails: findEmail already rejects every start the lookbehind skips, and findAndReplace retries a rejected match one character later. The fallback is only slower on long runs of word characters, and only on those old browsers. The loader is registered for webpack (`npm run build`) and Turbopack (`next dev`): Next 16 exits `next dev` when a `webpack` hook has no `turbopack` config. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Fixes #753
Problem
iOS/Safari 16.2 shows a blank page.
/bails out to client-side rendering, so one first-load script Safari cannot parse leaves nothing on screen. A production build of main has three:static {}block (Safari 16.4+): Next 16 targets Safari 16.4 by default and we had no browserslist.lib/markdown.tshas two RegExp lookbehind literals (Safari 16.4+).[email protected](via remark-gfm) has a lookbehind in its email regex; upstream declined to change it (New 'negative lookbehind' regex breaks in IOS & Safari versions < 16.4 syntax-tree/mdast-util-gfm-autolink-literal#10).Mermaid's lazily loaded chunks also contain ~270 static blocks, which would break diagrams.
Changes
package.json:browserslist= Next's defaults withsafari 16.2/ios_saf 16.2, so SWC compiles static blocks to private static fields.next.config.ts:transpilePackages: ["mermaid", "@mermaid-js/parser"], since node_modules otherwise keep the syntax they ship.lib/markdown.ts: both lookbehind regexes replaced byreplaceNotPrecededBy()+ sticky patterns with identical results.lib/gfm-autolink-email-loader.cjs+next.config.ts: a loader (webpack and Turbopack) builds the email regex at runtime and falls back to the 2.0.0 regex where lookbehind is unsupported (same matches;findEmailalready rejects what the lookbehind skips). It fails the build if upstream changes the regex.AGENTS.md: notes on the Safari 16.2 baseline.Testing
node --experimental-strip-types --test lib/markdown.test.mjs lib/gfm-autolink-email-loader.test.mjs, including differential tests against the old lookbehind regexes (20k generated lines each).npm run build, then scanned.next/static/**/*.jswith acorn: before, 26 files with 279 class static blocks and 2 lookbehind regex literals (3 first-load chunks affected); after, 0 static blocks and 0 lookbehind regex literals (the email regex only appears as a string insidetry), and nov-flag regexes. Total client JS grows by ~31 KiB (0.5%).next dev(Turbopack) starts,/returns 200, and the served chunk contains the rewritten email regex.tsc --noEmit, eslint.🤖 Generated with Claude Code