LibreChat/e2e/specs/mock
Danny Avila 562bd8ec5f
🐛 fix: Prevent Infinite Render Loop on Code-Execution File Preview (#13922)
* 🐛 fix: Prevent Infinite Render Loop on Code-Execution File Preview

Loading a conversation that contains a large (>1MB) code-execution
office file crashed the whole app with React error #185 ("Maximum
update depth exceeded") on hard refresh.

Root cause (client-only): the terminal-write effect in
useAttachmentPreviewSync writes the resolved preview record back into
messageAttachmentsMap with a fresh object identity on every run, and
`attachment` is in the effect's dependency array. useAttachments
re-derives `attachment` ({...db, ...liveEntry}) with a new identity on
every map write, so once polling resolves (pending -> ready on a loaded
conversation) the effect ping-pongs forever:
setAttachmentsMap -> re-derive -> effect -> setAttachmentsMap.

Only files large/slow enough to defer extraction are persisted at
status: 'pending', which is why small documents never triggered it.

Fix: an idempotency gate that bails before setAttachmentsMap when the
merged attachment already carries the resolved status/text/textFormat/
previewError. The write happens once and then settles.

Tests:
- useAttachmentPreviewSync.loop.spec.tsx wires the real
  useAttachments -> hook feedback to reproduce the loop (verified to
  throw #185 without the gate, settle with it).
- e2e/specs/mock/attachment-preview-loop.spec.ts loads a conversation
  with a pending code-exec attachment whose preview resolves ready and
  asserts the app does not crash.

Closes #13916

* 🔧 feat: Make Office Preview Extraction Cap Configurable (default 2MB)

The inline code-execution preview extraction ceiling was a hardcoded 1MB
constant (MAX_TEXT_EXTRACT_BYTES). Office/text artifacts over that skip
the inline preview and resolve to "Preview unavailable" (download-only).

Make it configurable via FILE_PREVIEW_MAX_EXTRACT_BYTES and raise the
default to 2MB so larger documents get an inline preview out of the box.
The rendered HTML remains independently capped at MAX_TEXT_CACHE_BYTES
(512KB), so image-heavy files over that still fall back to the existing
"preview too large" banner rather than rendering unbounded output.

- resolveMaxTextExtractBytes(env) parses the override, falling back to
  2MB on missing/non-numeric/non-positive values (warns on invalid).
- Documented in .env.example next to the other file-size limits.
- Unit tests cover default, valid override, fractional flooring, and
  invalid fallback.

* 🐛 fix: Guard sub-byte preview cap from flooring to zero

A fractional FILE_PREVIEW_MAX_EXTRACT_BYTES in (0, 1) passed the
positive-number check then floored to 0, making MAX_TEXT_EXTRACT_BYTES
zero and treating every non-empty artifact as oversized. Floor first,
then require the result to be >= 1 byte before accepting it; otherwise
fall back to the 2 MB default. Adds coverage for the sub-byte case.

*  test: Make exported-ceiling assertion env-independent

The "exported ceiling" assertion compared MAX_TEXT_EXTRACT_BYTES to a
literal 2 MB, but that const is initialized from
FILE_PREVIEW_MAX_EXTRACT_BYTES at module load — so the suite would
falsely fail when run with the override set. Assert the export tracks
resolveMaxTextExtractBytes(env) for the current environment instead; the
undefined-case test continues to pin the 2 MB default.
2026-06-23 16:34:43 -04:00
..
agents.helpers.ts ci: Add mock e2e coverage for agents, prompts, MCP, and chat flows (#13589) 2026-06-10 09:06:52 -04:00
agents.spec.ts 🎛️ feat: Redesign Settings with Registry-Driven Dialog, Search, and Mobile Drill-In (#13722) 2026-06-18 08:51:07 -04:00
app-load.spec.ts ci: Add mock e2e coverage for agents, prompts, MCP, and chat flows (#13589) 2026-06-10 09:06:52 -04:00
attachment-preview-loop.spec.ts 🐛 fix: Prevent Infinite Render Loop on Code-Execution File Preview (#13922) 2026-06-23 16:34:43 -04:00
auth.spec.ts 🛬 fix: Coalesce Auth Recovery into a Single Refresh Flight (#13618) 2026-06-09 12:04:12 -04:00
bookmarks.spec.ts 🔖 fix: Decrement Bookmark Counts When Deleting Conversations (#13830) 2026-06-18 08:37:08 -04:00
chat.spec.ts 🌿 fix: Preserve Viewed Branch on Sibling-Tree Churn (#13732) 2026-06-14 09:38:06 -04:00
conversation-management.spec.ts ci: Add mock e2e coverage for agents, prompts, MCP, and chat flows (#13589) 2026-06-10 09:06:52 -04:00
deployment-skills.spec.ts 🗂️ feat: Add Deployment Skill Directory (#13523) 2026-06-05 10:24:28 -04:00
enforced-model-specs.spec.ts 🪃 fix: Restore Raw Spec Fallback for Enforced Presets (#13804) 2026-06-16 21:10:22 -04:00
helpers.ts 🔌 fix: Preserve Ephemeral MCP Selections Across Model Switches (#13697) 2026-06-11 18:13:41 -04:00
isolation.spec.ts 🎭 feat: Add Credential-Free Playwright Smoke Suite with a Local Mock LLM (#13472) 2026-06-02 16:36:39 -04:00
mcp-allowlist-override.spec.ts 🔐 fix: Honor Admin-Panel MCP Allowlist Overrides Without Restart (#13814) 2026-06-17 20:14:53 -04:00
mcp-ephemeral.spec.ts 🔌 fix: Preserve Ephemeral MCP Selections Across Model Switches (#13697) 2026-06-11 18:13:41 -04:00
mcp.spec.ts ci: Add mock e2e coverage for agents, prompts, MCP, and chat flows (#13589) 2026-06-10 09:06:52 -04:00
message-tree.spec.ts 🌿 fix: Preserve Viewed Branch on Sibling-Tree Churn (#13732) 2026-06-14 09:38:06 -04:00
model-spec-branding.spec.ts feat: Surface Model Spec Branding on Landing and Selector (#13662) 2026-06-10 21:02:22 -04:00
model-spec-icons.spec.ts 🪞 fix: Preserve Model Spec Icons Across Stream Resume and Abort (#13603) 2026-06-08 17:14:21 -04:00
model-spec-skills.spec.ts 🧭 feat: Scope Model Spec Skills (#13522) 2026-06-05 10:22:02 -04:00
model-spec-starters.spec.ts 💬 feat: Conversation Starters for Model Specs (#13710) 2026-06-13 11:38:49 -04:00
model-switching.spec.ts 🎭 feat: Add Credential-Free Playwright Smoke Suite with a Local Mock LLM (#13472) 2026-06-02 16:36:39 -04:00
permissions.spec.ts 🪪 fix: Filter ACL Principal Details (#13524) 2026-06-05 19:06:41 -04:00
projects.spec.ts 📌 fix: Preserve Project Scope Through Enforced Model Specs (#13586) 2026-06-08 08:41:27 -04:00
prompts.spec.ts ci: Add mock e2e coverage for agents, prompts, MCP, and chat flows (#13589) 2026-06-10 09:06:52 -04:00
quotes.spec.ts 🖱️ fix: Summon Quote Popup on Double-Click Word Selection (#13923) 2026-06-23 15:52:34 -04:00
shared-links.spec.ts 🔗 feat: Add Granular Access Control to Shared Links via ACL System (#13051) 2026-06-03 14:17:17 -04:00
sidebar.spec.ts 📐 fix: Sidebar Chat List Width Tracking and Stale Row Measurements (#13655) 2026-06-10 13:27:18 -04:00
skill-file-authoring.spec.ts 📌 fix: Preserve Project Scope Through Enforced Model Specs (#13586) 2026-06-08 08:41:27 -04:00
soft-default.spec.ts 🪶 refactor: Ground Default Model Spec Selection in Conversation Recency (#13915) 2026-06-23 15:49:04 -04:00
two-factor.spec.ts 🧪 test: Add E2E Regression For 2FA framer-motion Crash (#13513) 2026-06-04 13:25:02 -04:00
usage.spec.ts 🪙 feat: Context Gauge UX, Hover Snapshot, Click Breakdown, Currency, Cost-On-By-Default (#13739) 2026-06-14 13:38:27 -04:00