Skip to content

Commit 5c0f786

Browse files
committed
fix(chat): drop unsafe toSorted, keep code-split + Map lookup
toSorted (ES2023) is not polyfilled by SWC and crashes iOS15/Safari<16 in client bundles, so revert use-skill-auto-mention to the non-mutating [...arr].sort() it had. The code-split of MothershipView and the first-match Map lookup in prompt-editor are unaffected. Tighten the sim-imports code-split note to state webpack *can* retain the barrel edge (removing the dead re-export is the guaranteed fix).
1 parent 84051e2 commit 5c0f786

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

.claude/rules/sim-imports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Dashboard } from '@/app/workspace/[workspaceId]/logs/components/dashboa
3333

3434
## Code-splitting through barrels
3535

36-
When you `lazy(() => import(...))` a component to keep it out of a route's initial bundle, import the **deep module path** (`./components/foo/foo`), never the barrel — and **delete the now-dead barrel re-export** of that component. This app has no `"sideEffects": false` in `apps/sim/package.json`, so webpack keeps a barrel's re-export edge to the heavy module whenever any sibling still imports that barrel. A leftover `export { Foo } from './foo'` line therefore drags `Foo` (and its transitive deps) back into the initial chunk and silently defeats the split. Verify the split with a production bundle diff, not just by eyeballing the `lazy()` call.
36+
When you `lazy(() => import(...))` a component to keep it out of a route's initial bundle, import the **deep module path** (`./components/foo/foo`), never the barrel — and **delete the now-dead barrel re-export** of that component. This app has no `"sideEffects": false` in `apps/sim/package.json`, so when any sibling still imports that barrel, webpack can conservatively keep the barrel's re-export edge to the heavy module. A leftover `export { Foo } from './foo'` line can therefore drag `Foo` (and its transitive deps) back into the initial chunk and silently defeat the split. Removing the dead re-export is the guaranteed fix; verify with a production bundle diff, not by eyeballing the `lazy()` call.
3737

3838
```typescript
3939
// ✓ Good — deep lazy import + no barrel edge left behind

apps/sim/app/workspace/[workspaceId]/home/components/user-input/hooks/use-skill-auto-mention.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export function useSkillAutoMention({ skills, setSelectedContexts }: UseSkillAut
176176
// descending so earlier replacements don't shift later indices; the
177177
// sentinel is one code unit wide like '/'.
178178
let result = text
179-
for (const idx of slashIndices.toSorted((a, b) => b - a)) {
179+
for (const idx of [...slashIndices].sort((a, b) => b - a)) {
180180
result = result.slice(0, idx) + SKILL_CHIP_TRIGGER + result.slice(idx + 1)
181181
}
182182
return result

0 commit comments

Comments
 (0)