Fix conversation crash on browsers without iterator helpers #3600

Open
lambadalambda wants to merge 1 commit from fix/iterator-helpers into develop

Opening a conversation on Firefox < 131 or Safari < 18.4 fails with t.entries().forEach is not a function (reported on shitposter.world). useTreeConversationTopology and usePleromaChat call forEach/reduce on Map iterators. .browserslistrc still lists Firefox 115/ESR and Safari 15, and nothing polyfills this.

  • Use Map.prototype.forEach or spread the iterator into an array.
  • Add a test fixture that hides Iterator.prototype helpers, with tests for both composables.

Testing: yarn unit-ci passes (520 tests), and the new tests fail without the fix.

Opening a conversation on Firefox < 131 or Safari < 18.4 fails with `t.entries().forEach is not a function` (reported on shitposter.world). `useTreeConversationTopology` and `usePleromaChat` call `forEach`/`reduce` on Map iterators. `.browserslistrc` still lists Firefox 115/ESR and Safari 15, and nothing polyfills this. - Use `Map.prototype.forEach` or spread the iterator into an array. - Add a test fixture that hides `Iterator.prototype` helpers, with tests for both composables. Testing: `yarn unit-ci` passes (520 tests), and the new tests fail without the fix.
fix: avoid iterator helpers in conversation and chat
All checks were successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/test-e2e Pipeline was successful
590f2ed898
Iterator.prototype.forEach/reduce need Firefox 131+ and Safari 18.4+,
but we support older browsers. Opening a conversation crashed there.
Author
Owner

/oc review

/oc review
opencode-fix-bot left a comment

Verdict

No defects found. This PR is production-ready.

Rating: 5/5

What I checked

  • Inspected the complete develop to fix/iterator-helpers diff (6 files, +66/-4).
  • Read the surrounding code in src/composables/useTreeConversationTopology.js and src/composables/usePleromaChat.js.
  • Searched src/ for remaining iterator-helper call chains (values()/keys()/entries() followed by forEach/map/reduce/etc.): none remain.
  • Ran the two affected spec files in headless Chromium: 11/11 tests pass, including the 2 new regression tests.
  • Red check: temporarily restored the base versions of the two source files and re-ran the specs — exactly the 2 new tests fail, confirming they reproduce the reported crash. The worktree was restored byte-for-byte to the claimed head afterward.

Why the fix is correct

  • parentMap.entries().forEach(([originId, originSet]) => ...) becomes parentMap.forEach((originSet) => ...): the destructured originId was unused, and Map.prototype.forEach is ES2015, so this is behavior-preserving on every supported browser.
  • sizes.keys().reduce(...) and depths.keys().reduce(...) become [...sizes.keys()].reduce(...) and [...depths.keys()].reduce(...): spreading a Map iterator into an array uses Symbol.iterator (ES2015) and then Array.prototype.reduce, avoiding the ES2025 iterator helpers entirely.
  • messageRetriers.value.values().forEach(...) becomes messageRetriers.value.forEach(...): same reasoning, Map.prototype.forEach.
  • The hideIteratorHelpers fixture deletes the Iterator.prototype helpers and restores them afterward (sync restore in the chat spec via try/finally, beforeEach/afterEach in the topology spec), so it faithfully simulates Firefox below 131 and Safari below 18.4 in the test browser.
  • The changelog fragment matches the repository changelog.d/ convention.

No findings to report, so nothing to consolidate or rank.

opencode-agent:job=166:generation=1

### Verdict No defects found. This PR is production-ready. **Rating: 5/5** ### What I checked - Inspected the complete `develop` to `fix/iterator-helpers` diff (6 files, +66/-4). - Read the surrounding code in `src/composables/useTreeConversationTopology.js` and `src/composables/usePleromaChat.js`. - Searched `src/` for remaining iterator-helper call chains (`values()`/`keys()`/`entries()` followed by `forEach`/`map`/`reduce`/etc.): none remain. - Ran the two affected spec files in headless Chromium: **11/11 tests pass**, including the 2 new regression tests. - Red check: temporarily restored the base versions of the two source files and re-ran the specs — exactly the 2 new tests fail, confirming they reproduce the reported crash. The worktree was restored byte-for-byte to the claimed head afterward. ### Why the fix is correct - `parentMap.entries().forEach(([originId, originSet]) => ...)` becomes `parentMap.forEach((originSet) => ...)`: the destructured `originId` was unused, and `Map.prototype.forEach` is ES2015, so this is behavior-preserving on every supported browser. - `sizes.keys().reduce(...)` and `depths.keys().reduce(...)` become `[...sizes.keys()].reduce(...)` and `[...depths.keys()].reduce(...)`: spreading a Map iterator into an array uses `Symbol.iterator` (ES2015) and then `Array.prototype.reduce`, avoiding the ES2025 iterator helpers entirely. - `messageRetriers.value.values().forEach(...)` becomes `messageRetriers.value.forEach(...)`: same reasoning, `Map.prototype.forEach`. - The `hideIteratorHelpers` fixture deletes the `Iterator.prototype` helpers and restores them afterward (sync restore in the chat spec via `try/finally`, `beforeEach`/`afterEach` in the topology spec), so it faithfully simulates Firefox below 131 and Safari below 18.4 in the test browser. - The changelog fragment matches the repository `changelog.d/` convention. No findings to report, so nothing to consolidate or rank. opencode-agent:job=166:generation=1
All checks were successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/test-e2e Pipeline was successful
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix/iterator-helpers:fix/iterator-helpers
git switch fix/iterator-helpers

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch develop
git merge --no-ff fix/iterator-helpers
git switch fix/iterator-helpers
git rebase develop
git switch develop
git merge --ff-only fix/iterator-helpers
git switch fix/iterator-helpers
git rebase develop
git switch develop
git merge --no-ff fix/iterator-helpers
git switch develop
git merge --squash fix/iterator-helpers
git switch develop
git merge --ff-only fix/iterator-helpers
git switch develop
git merge fix/iterator-helpers
git push origin develop
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pleroma/pleroma-fe!3600
No description provided.