Skip to content

Commit 3ed1022

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-32280
2 parents db47e11 + 006d7e3 commit 3ed1022

9 files changed

Lines changed: 179 additions & 36 deletions

File tree

‎apps/mobile/deps/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
The Enriched Markdown tarball comes from Julius's [`fork/t3-mobile` branch](https://github.com/pingdotgg/enriched-markdown/tree/fork/t3-mobile). Its `t3-fork.json` records the exact source commit and upstream base. React block renderers and signed image sources (`renderers`, `resolveImageSource`) are upstream. The fork carries native streaming memory bounds (an 8 MiB measurement-key budget and coalesced pending renders), plus changes with an open upstream PR: the `onLinksChange` link list that link pills and iOS link menus read ([#1088](https://github.com/software-mansion/enriched-markdown/pull/1088)), Android inline image alignment ([#1089](https://github.com/software-mansion/enriched-markdown/pull/1089)), clipboard link metadata ([#962](https://github.com/software-mansion/enriched-markdown/pull/962)), development-host autolinks ([#961](https://github.com/software-mansion/enriched-markdown/pull/961)), and `md4cFlags.preserveWindowsPaths`, which keeps backslashes in Windows drive paths in prose ([#1105](https://github.com/software-mansion/enriched-markdown/pull/1105), after [md4c#5](https://github.com/software-mansion-labs/md4c/pull/5)).
22

33
To replace it, commit the fork changes, run `yarn install --immutable` and `yarn workspace react-native-enriched-markdown prepare` in the fork checkout, then `node scripts/pack-t3.mjs /path/to/t3code/apps/mobile/deps`. Keep the package version aligned with Julius's `fork/t3-mobile` branch. Rename the archive to include the first eight characters of the source commit, such as `react-native-enriched-markdown-1.2.0-t3.16-8d2f84a8.tgz`, so each build has a distinct dependency path without version bumps. Update the tarball path in `apps/mobile/package.json` and `pnpm-workspace.yaml`'s `allowBuilds`, and run `vp i` to update the lockfile. Native clients need rebuilding when this dependency changes.
4+
5+
`patches/[email protected]` writes a newline inside a copied table cell as `<br>`, so Copy as Markdown keeps the row whole. It is not in the fork yet; fold it into `fork/t3-mobile` or drop it when you replace the tarball, since pnpm applies it to any archive with the same version.

‎apps/mobile/src/features/threads/thread-work-log.tsx‎

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
import {
3535
Animated as NativeAnimated,
3636
type ColorValue,
37-
Easing,
3837
Pressable,
3938
ScrollView,
4039
StyleSheet,
@@ -105,10 +104,9 @@ import Animated, {
105104
import { useAssetUrl } from "../../state/assets";
106105
import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
107106
import { useOpenLinkedThread } from "./useOpenLinkedThread";
107+
import { startShimmerSteps } from "./work-shimmer-steps";
108108

109109
const SHIMMER_WIDTH = 72;
110-
const SHIMMER_SWEEP_MS = 1_350;
111-
const SHIMMER_PAUSE_MS = 1_450;
112110
const SHIMMER_ICON_AND_GAP_WIDTH = 30;
113111
export const THREAD_DISCLOSURE_TRANSITION_MS = 180;
114112
const WORK_LOG_LAYOUT_TRANSITION = LinearTransition.duration(THREAD_DISCLOSURE_TRANSITION_MS);
@@ -269,44 +267,33 @@ export function ShimmeringWorkContent(props: {
269267
const appIsActive = useAppActive();
270268
const reducedMotion = useReduceMotionEnabled();
271269
const screenIsFocused = useIsFocused();
272-
const progress = useAnimatedValue(0);
270+
// Native from creation, so each setValue updates the view without a React render.
271+
const progress = useAnimatedValue(0, { useNativeDriver: true });
273272
const gradientId = `work-shimmer-${useId().replaceAll(":", "")}`;
274273
const contentWidth = Math.min(
275274
availableWidth,
276275
(props.showIcon ? SHIMMER_ICON_AND_GAP_WIDTH : 0) + Math.ceil(textWidth),
277276
);
278277

279-
// Runs on React Native's native driver instead of Reanimated, whose
280-
// per-frame commits starve React's while commit pausing is disabled
281-
// (package.json). See docs/internals/performance-regressions.md.
282-
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- starts the native-driver shimmer loop while visible and active, and stops it on cleanup
278+
// Uses a native Animated value instead of Reanimated, whose per-frame commits
279+
// starve React's while commit pausing is disabled (package.json). See
280+
// docs/internals/performance-regressions.md.
281+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- steps the native shimmer value on timers while visible and active, and stops them on cleanup
283282
useEffect(() => {
284283
progress.setValue(0);
285284
if (contentWidth <= 0 || reducedMotion || !appIsActive || !screenIsFocused) return;
286-
287-
const loop = NativeAnimated.loop(
288-
NativeAnimated.timing(progress, {
289-
toValue: 1,
290-
duration: SHIMMER_SWEEP_MS + SHIMMER_PAUSE_MS,
291-
easing: Easing.linear,
292-
useNativeDriver: true,
293-
}),
294-
);
295-
loop.start();
296-
return () => loop.stop();
285+
return startShimmerSteps(progress);
297286
}, [appIsActive, contentWidth, progress, reducedMotion, screenIsFocused]);
298287

299-
// One timing covers the sweep and the pause, so the native driver can loop it.
300288
// The React Compiler memoizes these, so re-renders don't rebuild the native
301289
// animation nodes.
302-
const inputRange = [0, SHIMMER_SWEEP_MS / (SHIMMER_SWEEP_MS + SHIMMER_PAUSE_MS), 1];
303290
const sweepTranslateX = progress.interpolate({
304-
inputRange,
305-
outputRange: [-SHIMMER_WIDTH, contentWidth, contentWidth],
291+
inputRange: [0, 1],
292+
outputRange: [-SHIMMER_WIDTH, contentWidth],
306293
});
307294
const counterSweepTranslateX = progress.interpolate({
308-
inputRange,
309-
outputRange: [SHIMMER_WIDTH, -contentWidth, -contentWidth],
295+
inputRange: [0, 1],
296+
outputRange: [SHIMMER_WIDTH, -contentWidth],
310297
});
311298

312299
return (
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, it, vi } from "vite-plus/test";
2+
3+
import {
4+
SHIMMER_PAUSE_MS,
5+
SHIMMER_STEPS,
6+
SHIMMER_SWEEP_MS,
7+
startShimmerSteps,
8+
} from "./work-shimmer-steps";
9+
10+
it("steps the sweep, stays quiet through the pause, and stops on cleanup", () => {
11+
using _timers = { [Symbol.dispose]: () => vi.useRealTimers() };
12+
vi.useFakeTimers();
13+
const values: number[] = [];
14+
const stop = startShimmerSteps({ setValue: (value) => values.push(value) });
15+
const valuesDuring = (ms: number) => {
16+
vi.advanceTimersByTime(ms);
17+
return values.splice(0);
18+
};
19+
20+
const sweep = valuesDuring(SHIMMER_SWEEP_MS);
21+
expect(sweep).toHaveLength(SHIMMER_STEPS);
22+
expect(sweep.at(-1)).toBe(1);
23+
expect(sweep).toEqual(Array.from({ length: SHIMMER_STEPS }, (_, i) => (i + 1) / SHIMMER_STEPS));
24+
expect(valuesDuring(SHIMMER_PAUSE_MS)).toEqual([]);
25+
expect(valuesDuring(SHIMMER_SWEEP_MS)).toEqual(sweep);
26+
27+
stop();
28+
expect(vi.getTimerCount()).toBe(0);
29+
expect(valuesDuring((SHIMMER_SWEEP_MS + SHIMMER_PAUSE_MS) * 2)).toEqual([]);
30+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const SHIMMER_SWEEP_MS = 1_350;
2+
export const SHIMMER_PAUSE_MS = 1_450;
3+
export const SHIMMER_STEPS = 12;
4+
const SHIMMER_STEP_MS = SHIMMER_SWEEP_MS / SHIMMER_STEPS;
5+
6+
// No progress updates run during the pause. Progress 0 and 1 both sit off the
7+
// content, so the cycle only needs steps 1 through SHIMMER_STEPS.
8+
export function startShimmerSteps(progress: { setValue(value: number): void }): () => void {
9+
let step = 0;
10+
let timer: ReturnType<typeof setTimeout>;
11+
const advance = () => {
12+
step = (step % SHIMMER_STEPS) + 1;
13+
progress.setValue(step / SHIMMER_STEPS);
14+
timer = setTimeout(
15+
advance,
16+
step === SHIMMER_STEPS ? SHIMMER_PAUSE_MS + SHIMMER_STEP_MS : SHIMMER_STEP_MS,
17+
);
18+
};
19+
timer = setTimeout(advance, SHIMMER_STEP_MS);
20+
return () => clearTimeout(timer);
21+
}

‎apps/mobile/src/lib/markdownDocument.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ function htmlTagMarkdown(
229229
const blockBreak = anchors.open === 0 ? "\n\n" : " ";
230230
if (/^<summary\b/i.test(tag)) return `${blockBreak}**`;
231231
if (/^<\/summary\s*>/i.test(tag)) return `**${blockBreak}`;
232-
// A line break would end the table row, so a cell keeps its content on one line.
233-
if (/^<br\b/i.test(tag)) return options.inTableCell ? " " : " \n";
232+
// A raw newline would end the table row; both parsers decode this reference to one inside the cell.
233+
if (/^<br\b/i.test(tag)) return options.inTableCell ? "&#10;" : " \n";
234234
if (/^<\/?(?:p|div|details)\b/i.test(tag)) return blockBreak;
235235
return "";
236236
}

‎apps/mobile/src/lib/markdownHtml.test.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,27 @@ describe("HTML in native Markdown", () => {
8585
expect(result).toContain('<img src="after.png">\n</details>');
8686
});
8787

88-
it("links HTML anchors in a table cell without breaking the row at <br>", () => {
89-
const document = parseMarkdownDocument(
90-
"| Status | Preview URL |\n| - | - |\n| Done | <a href='https://commit.example.com'>Commit</a><br><a href='https://branch.example.com'>Branch</a> |",
88+
it("keeps <br> line breaks in a table cell without breaking the row", () => {
89+
const markdown =
90+
"| Status | Preview URL |\n| - | - |\n| Done | <a href='https://commit.example.com'>Commit</a><br><a href='https://branch.example.com'>Branch</a> |\n| • One<br/>• Two<BR />**Three** | `<br>` |";
91+
// md4c decodes the reference to a newline in the cell's text, as remark does.
92+
expect(markdownForNativeRendering(markdown, ENRICHED_INLINE_FILE_LINK_REGEX)).toContain(
93+
"| • One&#10;• Two&#10;**Three** | `<br>` |",
9194
);
92-
const table = document.children[0];
95+
const table = parseMarkdownDocument(markdown).children[0];
9396
expect(table?.type).toBe("table");
9497
if (table?.type !== "table") return;
95-
expect(table.children).toHaveLength(2);
98+
expect(table.children).toHaveLength(3);
99+
expect(table.children.map((row) => row.children.length)).toEqual([2, 2, 2]);
96100
expect(table.children[1]?.children[1]?.children).toMatchObject([
97101
{ type: "link", url: "https://commit.example.com", children: [{ value: "Commit" }] },
98-
{ type: "text", value: " " },
102+
{ type: "text", value: "\n" },
99103
{ type: "link", url: "https://branch.example.com", children: [{ value: "Branch" }] },
100104
]);
105+
expect(table.children[2]?.children).toMatchObject([
106+
{ children: [{ value: "• One\n• Two\n" }, { type: "strong" }] },
107+
{ children: [{ type: "inlineCode", value: "<br>" }] },
108+
]);
101109
});
102110

103111
it("keeps a table row intact when an anchor href contains a pipe", () => {
@@ -121,7 +129,7 @@ describe("HTML in native Markdown", () => {
121129
const markdown =
122130
'> **!<a href="https://x.test">[one]</a>** and <span>tail</span>\n\n| A |\n| - |\n| !<a href="https://x.test">x[y]</a><br><img src="x.png"> |';
123131
expect(markdownWithHtml(markdown)).toBe(
124-
"> **\\![\\[one\\]](<https://x.test>)** and tail\n\n| A |\n| - |\n| \\![x\\[y\\]](<https://x.test>) ![](<x.png>) |",
132+
"> **\\![\\[one\\]](<https://x.test>)** and tail\n\n| A |\n| - |\n| \\![x\\[y\\]](<https://x.test>)&#10;![](<x.png>) |",
125133
);
126134
expect(
127135
markdownWithHtml(

‎patches/[email protected]‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
diff --git a/android/src/main/java/com/swmansion/enriched/markdown/segments/TableContainerView.kt b/android/src/main/java/com/swmansion/enriched/markdown/segments/TableContainerView.kt
2+
--- a/android/src/main/java/com/swmansion/enriched/markdown/segments/TableContainerView.kt
3+
+++ b/android/src/main/java/com/swmansion/enriched/markdown/segments/TableContainerView.kt
4+
@@ -131,7 +131,7 @@ class TableContainerView(
5+
TableCellData(
6+
attributedText = renderCellNode(cell, isHeader, align),
7+
plainText = extractPlainText(cell),
8+
- markdownText = MarkdownASTSerializer.serializeChildren(cell),
9+
+ markdownText = MarkdownASTSerializer.serializeTableCell(cell),
10+
isHeader = isHeader,
11+
alignment = align,
12+
)
13+
diff --git a/android/src/main/java/com/swmansion/enriched/markdown/utils/common/serialization/MarkdownASTSerializer.kt b/android/src/main/java/com/swmansion/enriched/markdown/utils/common/serialization/MarkdownASTSerializer.kt
14+
--- a/android/src/main/java/com/swmansion/enriched/markdown/utils/common/serialization/MarkdownASTSerializer.kt
15+
+++ b/android/src/main/java/com/swmansion/enriched/markdown/utils/common/serialization/MarkdownASTSerializer.kt
16+
@@ -20,6 +20,12 @@ object MarkdownASTSerializer {
17+
return buffer.toString()
18+
}
19+
20+
+ private val tableCellLineBreak = Regex("""(?<!\\)(\\*)\n""")
21+
+
22+
+ /** Serializes a table cell's content; a newline inside it becomes `<br>` so the row stays on one line. */
23+
+ fun serializeTableCell(cell: MarkdownASTNode): String =
24+
+ serializeChildren(cell).replace(tableCellLineBreak, "$1$1<br>")
25+
+
26+
/**
27+
* Serializes a Blockquote or Admonition node back to markdown, including
28+
* the `> ` prefix on every line and `> [!TYPE]` header for admonitions.
29+
@@ -179,7 +185,7 @@ object MarkdownASTSerializer {
30+
for (section in node.children) {
31+
for (row in section.children) {
32+
if (row.type != NodeType.TableRow) continue
33+
- val cells = row.children.map { serializeChildren(it) }
34+
+ val cells = row.children.map { serializeTableCell(it) }
35+
buffer.append("| ")
36+
buffer.append(cells.joinToString(" | "))
37+
buffer.append(" |\n")
38+
diff --git a/ios/segments/TableContainerView.m b/ios/segments/TableContainerView.m
39+
--- a/ios/segments/TableContainerView.m
40+
+++ b/ios/segments/TableContainerView.m
41+
@@ -163,7 +163,7 @@ static NSArray<NSArray<TableCellData *> *> *ENRMTableBuildRows(MarkdownASTNode *
42+
cell.isHeader = isSectionHead || (cellNode.type == MarkdownNodeTypeTableHeaderCell);
43+
cell.alignment = ENRMTableTextAlignmentFromString(cellNode.attributes[@"align"]);
44+
cell.plainText = ENRMTablePlainTextFromNode(cellNode);
45+
- cell.markdownText = markdownFromASTNodeChildren(cellNode);
46+
+ cell.markdownText = markdownFromTableCellNode(cellNode);
47+
48+
StyleConfig *cellConfig = cell.isHeader ? headerCellConfig : bodyCellConfig;
49+
cell.attributedText =
50+
diff --git a/ios/utils/MarkdownASTSerializer.h b/ios/utils/MarkdownASTSerializer.h
51+
--- a/ios/utils/MarkdownASTSerializer.h
52+
+++ b/ios/utils/MarkdownASTSerializer.h
53+
@@ -17,6 +17,9 @@ NSString *markdownFromASTNode(MarkdownASTNode *node);
54+
/// Useful for extracting the markdown content of a container node (e.g. a table cell).
55+
NSString *markdownFromASTNodeChildren(MarkdownASTNode *node);
56+
57+
+/// Serializes a table cell's content; a newline inside it becomes `<br>` so the row stays on one line.
58+
+NSString *markdownFromTableCellNode(MarkdownASTNode *node);
59+
+
60+
/// Serializes a Blockquote or Admonition node to full markdown, including `> ` line
61+
/// prefixes and `> [!TYPE]` header for admonitions.
62+
NSString *markdownFromBlockquoteNode(MarkdownASTNode *node);
63+
diff --git a/ios/utils/MarkdownASTSerializer.m b/ios/utils/MarkdownASTSerializer.m
64+
--- a/ios/utils/MarkdownASTSerializer.m
65+
+++ b/ios/utils/MarkdownASTSerializer.m
66+
@@ -148,7 +148,7 @@ static void appendTableMarkdown(MarkdownASTNode *node, NSMutableString *buffer)
67+
continue;
68+
NSMutableArray<NSString *> *cells = [NSMutableArray arrayWithCapacity:row.children.count];
69+
for (MarkdownASTNode *cell in row.children) {
70+
- [cells addObject:markdownFromASTNodeChildren(cell)];
71+
+ [cells addObject:markdownFromTableCellNode(cell)];
72+
}
73+
[buffer appendFormat:@"| %@ |\n", [cells componentsJoinedByString:@" | "]];
74+
if (!headerDone) {
75+
@@ -333,6 +333,17 @@ NSString *markdownFromASTNodeChildren(MarkdownASTNode *node)
76+
return [buffer copy];
77+
}
78+
79+
+NSString *markdownFromTableCellNode(MarkdownASTNode *node)
80+
+{
81+
+ NSString *markdown = markdownFromASTNodeChildren(node);
82+
+ if (![markdown containsString:@"\n"])
83+
+ return markdown;
84+
+ return [markdown stringByReplacingOccurrencesOfString:@"(?<!\\\\)(\\\\*)\n"
85+
+ withString:@"$1$1<br>"
86+
+ options:NSRegularExpressionSearch
87+
+ range:NSMakeRange(0, markdown.length)];
88+
+}
89+
+
90+
NSString *markdownFromBlockquoteNode(MarkdownASTNode *node)
91+
{
92+
if (!node)

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)