Skip to content

fix(compat): load on Safari and iOS 16.2 - #1019

Merged
agegr merged 2 commits into
mainfrom
claude/issue-753-safari-16-2
Sep 30, 2026
Merged

agegr merged 2 commits into
mainfrom
claude/issue-753-safari-16-2

Conversation

@agegr

@agegr agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

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:

Mermaid's lazily loaded chunks also contain ~270 static blocks, which would break diagrams.

Changes

  • package.json: browserslist = Next's defaults with safari 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 by replaceNotPrecededBy() + 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; findEmail already 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/**/*.js with 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 inside try), and no v-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.
  • Not verified on a real iOS 16.2 device; the reporter offered to check.

🤖 Generated with Claude Code

agegr and others added 2 commits September 30, 2026 21:36
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]>
@agegr
agegr merged commit f52fd84 into main Sep 30, 2026
2 checks passed
@agegr
agegr deleted the claude/issue-753-safari-16-2 branch October 1, 2026 13:28
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]>
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.

请求兼容 iOS 16.2 / Safari 16.2:首屏 JS 含 static block 与 lookbehind,手机打开整页空白

1 participant