mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
* chore(app): vendor react-native-enriched-markdown with the Paseo patch applied Copy react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67 (upstream software-mansion/enriched-markdown 766fc0e67) into packages/react-native-enriched-markdown, with patches/react-native-enriched-markdown+1.2.0-nightly-20261014-766fc0e67.patch applied. Nothing else changes in this commit; the package is not a workspace yet. Reproduce: npm pack react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67 tar xzf react-native-enriched-markdown-*.tgz mkdir -p t/node_modules && mv package t/node_modules/react-native-enriched-markdown (cd t && git init -q && git apply ../patches/react-native-enriched-markdown+*.patch) diff -r t/node_modules/react-native-enriched-markdown packages/react-native-enriched-markdown The diff is empty. * chore(app): consume react-native-enriched-markdown from its workspace Make packages/react-native-enriched-markdown a private workspace and point the app at it, then remove the patch-package patch it replaces. - package.json: private, version follows the root like every workspace, only the postinstall script that downloads tree-sitter grammars. Upstream's devDependencies would install a second react-native, so they are gone. - The package keeps its name, so autolinking, the Gradle project :react-native-enriched-markdown, the CocoaPods spec and imports are unchanged. - Lockfile: drop the nested registry copy under packages/app/node_modules; npm links node_modules/react-native-enriched-markdown to the workspace. - Formatting, lint and knip skip the vendored code. CI routes changes to it through the app and browser suites. - The codegen test checks the vendored package's generated props. - docs/markdown-renderer.md describes the fork and how to edit it. * fix(app): keep numbered sub-list markers off their text on Android From #9964, moved from the package patch into the vendored package. On Android, a numbered list nested in a bulleted item drew "1." over the first letters of each item. A nested item's text indent summed the root list's narrow bullet column with a fixed marginLeft, while its marker was right-aligned to its own wider "99." column, so the number landed on the text. iOS already indents from the item's own column. Backport the Android hunks of upstream enriched-markdown #1015 (size the number column to the widest marker) and #1023 (nested items start their text from their own marker column). test:android now also runs the backported ListRenderingTest and TaskListInteractionTest suites. docs/markdown-renderer.md lists the fork's backports, this one and #924, which the removed postinstall comment used to track. The vendored tree equals the #9964 patch applied to the pristine package. * fix(app): keep Android assistant replies inside their turns From #10380, moved from the package patch into the vendored package. On Android, an assistant reply with blockquotes nested inside a list could overlap its "Worked for ..." footer and the next user message: the displayed text and the layout measurement applied spans in different orders, and the list-wide line height inflated the blockquote spacers when it ran after them. Use the same span order for Android Markdown measurement and display. Apply list line height before blockquote spacers so nested quotes keep their configured padding and the reply fits above the turn footer. test:android now also runs ListBlockquoteMeasurementTest. Applied on top of #9964; the two changes share only ListRenderer.kt, where #10380's import and line-height call sit beside #9964's marker width code. Every other file equals the #10380 patch applied to the pristine package. * chore(app): match the vendored Markdown web block renderer source to its build The package patch changed lib/module/web/renderers/BlockRenderers.js (the renderers.codeBlock override and the zoom-in cursor on images) but not src/web/renderers/BlockRenderers.tsx. The app runs lib, so behavior does not change. Port both changes into src so src stays the source of lib.
426 lines
14 KiB
JavaScript
426 lines
14 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { spawnSync } from "node:child_process";
|
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
import { createRequire } from "node:module";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { test } from "node:test";
|
|
import vm from "node:vm";
|
|
|
|
const script = path.resolve("scripts", "postinstall-patches.mjs");
|
|
const bin = path.resolve("node_modules", ".bin");
|
|
const packageName = "react-native-draggable-flatlist";
|
|
const patchFile = `${packageName}+4.0.3.patch`;
|
|
|
|
for (const platform of ["ios", "android"]) {
|
|
test(`vendored Markdown ships ${platform} props generated from its native specs`, () => {
|
|
const packageDir = path.resolve("packages/react-native-enriched-markdown");
|
|
const output = mkdtempSync(path.join(tmpdir(), `markdown-${platform}-codegen-`));
|
|
try {
|
|
// includesGeneratedCode makes native builds use the shipped headers instead of
|
|
// regenerating them from the TypeScript specs, so a spec edit must regenerate them.
|
|
const result = spawnSync(
|
|
process.execPath,
|
|
[
|
|
path.resolve("node_modules/react-native/scripts/generate-codegen-artifacts.js"),
|
|
"-p",
|
|
packageDir,
|
|
"-t",
|
|
platform,
|
|
"-o",
|
|
output,
|
|
"-s",
|
|
"library",
|
|
],
|
|
{ encoding: "utf8" },
|
|
);
|
|
assert.equal(result.status, 0, result.stdout + result.stderr);
|
|
const header =
|
|
platform === "ios"
|
|
? "ReactCodegen/EnrichedMarkdownTextSpec/Props.h"
|
|
: "jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h";
|
|
assert.equal(
|
|
readFileSync(path.join(packageDir, platform, "generated", header), "utf8"),
|
|
readFileSync(path.join(output, header), "utf8"),
|
|
);
|
|
} finally {
|
|
rmSync(output, { recursive: true, force: true });
|
|
}
|
|
});
|
|
}
|
|
|
|
function createCheckout() {
|
|
const root = mkdtempSync(path.join(tmpdir(), "postinstall-patches-"));
|
|
writeFileSync(path.join(root, "package.json"), JSON.stringify({ name: "checkout" }));
|
|
const packageDir = path.join(root, "node_modules", packageName);
|
|
mkdirSync(packageDir, { recursive: true });
|
|
writeFileSync(
|
|
path.join(packageDir, "package.json"),
|
|
JSON.stringify({ name: packageName, version: "4.0.3" }),
|
|
);
|
|
writeFileSync(path.join(packageDir, "index.js"), "export const value = 1;\n");
|
|
mkdirSync(path.join(root, "patches"));
|
|
return { root, packageDir };
|
|
}
|
|
|
|
function writePatch(root, from, to) {
|
|
const file = `node_modules/${packageName}/index.js`;
|
|
writeFileSync(
|
|
path.join(root, "patches", patchFile),
|
|
[
|
|
`diff --git a/${file} b/${file}`,
|
|
`--- a/${file}`,
|
|
`+++ b/${file}`,
|
|
"@@ -1 +1 @@",
|
|
`-export const value = ${from};`,
|
|
`+export const value = ${to};`,
|
|
"",
|
|
].join("\n"),
|
|
);
|
|
}
|
|
|
|
function install(root, PATH = `${bin}${path.delimiter}${process.env.PATH}`) {
|
|
return spawnSync(process.execPath, [script], {
|
|
cwd: root,
|
|
encoding: "utf8",
|
|
env: { ...process.env, PATH },
|
|
});
|
|
}
|
|
|
|
test("a patch that changed since it was applied removes the package for a clean reinstall", () => {
|
|
const { root, packageDir } = createCheckout();
|
|
try {
|
|
writePatch(root, 1, 2);
|
|
assert.equal(install(root).status, 0);
|
|
assert.equal(
|
|
readFileSync(path.join(packageDir, "index.js"), "utf8"),
|
|
"export const value = 2;\n",
|
|
);
|
|
|
|
writePatch(root, 1, 3);
|
|
const result = install(root);
|
|
|
|
assert.equal(result.status, 1);
|
|
assert.match(result.stderr, /Run npm install again/);
|
|
assert.equal(existsSync(packageDir), false);
|
|
} finally {
|
|
rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("an already applied patch leaves the package in place", () => {
|
|
const { root, packageDir } = createCheckout();
|
|
try {
|
|
writePatch(root, 1, 2);
|
|
assert.equal(install(root).status, 0);
|
|
assert.equal(install(root).status, 0);
|
|
assert.equal(
|
|
readFileSync(path.join(packageDir, "index.js"), "utf8"),
|
|
"export const value = 2;\n",
|
|
);
|
|
} finally {
|
|
rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("a missing patch-package fails the install and leaves the package in place", () => {
|
|
const { root, packageDir } = createCheckout();
|
|
try {
|
|
writePatch(root, 1, 2);
|
|
const result = install(root, root);
|
|
|
|
assert.equal(result.status, 1);
|
|
assert.match(result.stderr, /failed to spawn/);
|
|
assert.equal(existsSync(packageDir), true);
|
|
} finally {
|
|
rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
function loadReactFabricDispatchEvent(bundleName, isDev) {
|
|
const bundlePath = path.resolve(
|
|
"node_modules/react-native/Libraries/Renderer/implementations",
|
|
bundleName,
|
|
);
|
|
const code = readFileSync(bundlePath, "utf8");
|
|
const nodeRequire = createRequire(import.meta.url);
|
|
let dispatchEvent = null;
|
|
const warnings = [];
|
|
const rawEventListeners = new Map();
|
|
|
|
const nativeFabricUIManager = {
|
|
createNode: () => ({}),
|
|
cloneNodeWithNewChildren: () => ({}),
|
|
cloneNodeWithNewChildrenAndProps: () => ({}),
|
|
cloneNodeWithNewProps: () => ({}),
|
|
createChildSet: () => ({}),
|
|
appendChild: () => {},
|
|
appendChildToSet: () => {},
|
|
completeRoot: () => {},
|
|
registerEventHandler: (fn) => {
|
|
dispatchEvent = fn;
|
|
},
|
|
setIsJSResponder: () => {},
|
|
clearIsJSResponder: () => {},
|
|
unstable_DiscreteEventPriority: 1,
|
|
unstable_ContinuousEventPriority: 2,
|
|
unstable_IdleEventPriority: 3,
|
|
unstable_getCurrentEventPriority: () => 1,
|
|
};
|
|
|
|
const privateInterface = {
|
|
ReactNativeViewConfigRegistry: {
|
|
get: () => ({}),
|
|
customBubblingEventTypes: {
|
|
topTouchStart: {
|
|
phasedRegistrationNames: { bubbled: "onTouchStart", captured: "onTouchStartCapture" },
|
|
},
|
|
topTouchMove: {
|
|
phasedRegistrationNames: { bubbled: "onTouchMove", captured: "onTouchMoveCapture" },
|
|
},
|
|
topTouchEnd: {
|
|
phasedRegistrationNames: { bubbled: "onTouchEnd", captured: "onTouchEndCapture" },
|
|
},
|
|
topTouchCancel: {
|
|
phasedRegistrationNames: { bubbled: "onTouchCancel", captured: "onTouchCancelCapture" },
|
|
},
|
|
topSelectionChange: {
|
|
phasedRegistrationNames: {
|
|
bubbled: "onSelectionChange",
|
|
captured: "onSelectionChangeCapture",
|
|
},
|
|
},
|
|
},
|
|
customDirectEventTypes: {},
|
|
},
|
|
RawEventEmitter: {
|
|
emit: (name, payload) => {
|
|
for (const fn of rawEventListeners.get(name) ?? []) {
|
|
fn(payload);
|
|
}
|
|
},
|
|
},
|
|
UIManager: {},
|
|
deepDiffer: () => false,
|
|
flattenStyle: (s) => s,
|
|
getNativeTagFromPublicInstance: () => null,
|
|
getNodeFromPublicInstance: () => null,
|
|
legacySendAccessibilityEvent: () => {},
|
|
createPublicInstance: (tag) => ({ _nativeTag: tag }),
|
|
createPublicTextInstance: () => ({}),
|
|
ReactFiberErrorDialog: { showErrorDialog: () => true },
|
|
Platform: { OS: "android" },
|
|
};
|
|
|
|
const customRequire = (id) => {
|
|
if (id === "react") {
|
|
return nodeRequire("react");
|
|
}
|
|
if (id === "scheduler") {
|
|
return nodeRequire("scheduler");
|
|
}
|
|
if (id === "react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore") {
|
|
return {};
|
|
}
|
|
if (id === "react-native/Libraries/ReactPrivate/ReactNativePrivateInterface") {
|
|
return privateInterface;
|
|
}
|
|
return nodeRequire(id);
|
|
};
|
|
|
|
const moduleObj = { exports: {} };
|
|
const sandbox = {
|
|
__DEV__: isDev,
|
|
console: {
|
|
...console,
|
|
warn: (...args) => warnings.push(args.join(" ")),
|
|
error: (...args) => warnings.push(args.join(" ")),
|
|
},
|
|
exports: moduleObj.exports,
|
|
module: moduleObj,
|
|
nativeFabricUIManager,
|
|
performance,
|
|
queueMicrotask,
|
|
require: customRequire,
|
|
setTimeout,
|
|
clearTimeout,
|
|
};
|
|
sandbox.global = sandbox;
|
|
sandbox.globalThis = sandbox;
|
|
|
|
vm.runInNewContext(code, sandbox, { filename: bundleName });
|
|
assert.equal(
|
|
typeof dispatchEvent,
|
|
"function",
|
|
`Expected ${bundleName} to register dispatchEvent`,
|
|
);
|
|
return { dispatchEvent, warnings };
|
|
}
|
|
|
|
function createHostFiber(type, props, parent = null) {
|
|
const publicInstance = { _nativeTag: Math.floor(Math.random() * 100000) + 1 };
|
|
return {
|
|
tag: 5,
|
|
type,
|
|
return: parent,
|
|
alternate: null,
|
|
stateNode: {
|
|
canonical: {
|
|
currentProps: props,
|
|
publicInstance,
|
|
publicInstanceType: 0,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
function makeTouch(identifier, timestamp) {
|
|
return {
|
|
identifier,
|
|
target: 1,
|
|
pageX: 100,
|
|
pageY: 100,
|
|
locationX: 10,
|
|
locationY: 10,
|
|
timestamp,
|
|
};
|
|
}
|
|
|
|
for (const [bundleName, isDev] of [
|
|
["ReactFabric-dev.js", true],
|
|
["ReactFabric-prod.js", false],
|
|
["ReactFabric-profiling.js", false],
|
|
]) {
|
|
test(`${bundleName} reconciles trackedTouchCount from nativeEvent.touches after a dropped touch end`, () => {
|
|
const { dispatchEvent, warnings } = loadReactFabricDispatchEvent(bundleName, isDev);
|
|
const rootFiber = createHostFiber("RCTView", {});
|
|
let inputGrants = 0;
|
|
let buttonGrants = 0;
|
|
const inputFiber = createHostFiber(
|
|
"PasteTextInput",
|
|
{
|
|
onSelectionChangeShouldSetResponder: () => true,
|
|
onResponderGrant: () => {
|
|
inputGrants += 1;
|
|
},
|
|
},
|
|
rootFiber,
|
|
);
|
|
const buttonFiber = createHostFiber(
|
|
"RCTView",
|
|
{
|
|
onStartShouldSetResponder: () => true,
|
|
onResponderGrant: () => {
|
|
buttonGrants += 1;
|
|
},
|
|
},
|
|
rootFiber,
|
|
);
|
|
|
|
// 1. Unmatched touch start (e.g. Modal dismissed while touch is down or double ACTION_DOWN).
|
|
const orphanTouch = makeTouch(0, 1);
|
|
dispatchEvent(rootFiber, "topTouchStart", {
|
|
touches: [orphanTouch],
|
|
changedTouches: [orphanTouch],
|
|
});
|
|
|
|
// 2. Subsequent normal tap completes with zero remaining native touches.
|
|
const tapTouch = makeTouch(1, 2);
|
|
dispatchEvent(inputFiber, "topTouchStart", {
|
|
touches: [tapTouch],
|
|
changedTouches: [tapTouch],
|
|
});
|
|
dispatchEvent(inputFiber, "topTouchEnd", {
|
|
touches: [],
|
|
changedTouches: [tapTouch],
|
|
});
|
|
|
|
// 3. Typing triggers topSelectionChange. With trackedTouchCount reconciled to 0,
|
|
// the input must not claim responder and swallow the next tap on a sibling button.
|
|
dispatchEvent(inputFiber, "topSelectionChange", {
|
|
selection: { start: 1, end: 1 },
|
|
});
|
|
assert.equal(
|
|
inputGrants,
|
|
0,
|
|
"topSelectionChange must not claim responder when no touches are active",
|
|
);
|
|
|
|
// 4. First tap on sibling send button must be granted immediately.
|
|
const sendTouch = makeTouch(2, 3);
|
|
dispatchEvent(buttonFiber, "topTouchStart", {
|
|
touches: [sendTouch],
|
|
changedTouches: [sendTouch],
|
|
});
|
|
dispatchEvent(buttonFiber, "topTouchEnd", {
|
|
touches: [],
|
|
changedTouches: [sendTouch],
|
|
});
|
|
assert.equal(buttonGrants, 1, "first tap on sibling button must receive responder grant");
|
|
|
|
// 5. Two-finger gesture cancelled by a single synthetic topTouchCancel (e.g. RNGH pinch takeover)
|
|
// must reconcile trackedTouchCount to 0 and mark every touchBank contact inactive before
|
|
// onResponderTerminate runs.
|
|
let terminatedHistory = null;
|
|
const gestureFiber = createHostFiber(
|
|
"RCTView",
|
|
{
|
|
onStartShouldSetResponder: () => true,
|
|
onResponderTerminate: (event) => {
|
|
terminatedHistory = {
|
|
numberActiveTouches: event.touchHistory.numberActiveTouches,
|
|
activeBankIds: Array.from(event.touchHistory.touchBank, (record, index) =>
|
|
record?.touchActive ? index : -1,
|
|
).filter((index) => index >= 0),
|
|
};
|
|
},
|
|
},
|
|
rootFiber,
|
|
);
|
|
const p0 = makeTouch(3, 4);
|
|
const p1 = makeTouch(4, 5);
|
|
dispatchEvent(gestureFiber, "topTouchStart", { touches: [p0], changedTouches: [p0] });
|
|
dispatchEvent(gestureFiber, "topTouchStart", { touches: [p0, p1], changedTouches: [p1] });
|
|
dispatchEvent(gestureFiber, "topTouchCancel", { touches: [], changedTouches: [p0] });
|
|
assert.deepEqual(terminatedHistory, {
|
|
numberActiveTouches: 0,
|
|
activeBankIds: [],
|
|
});
|
|
dispatchEvent(inputFiber, "topSelectionChange", { selection: { start: 2, end: 2 } });
|
|
assert.equal(
|
|
inputGrants,
|
|
0,
|
|
"single topTouchCancel after 2-finger touch must reset trackedTouchCount to 0",
|
|
);
|
|
|
|
// 6. Multi-touch cancel emitting two topTouchCancel events with touches: [] must stay at 0 without warning.
|
|
const t0 = makeTouch(5, 6);
|
|
const t1 = makeTouch(6, 7);
|
|
dispatchEvent(rootFiber, "topTouchStart", { touches: [t0], changedTouches: [t0] });
|
|
dispatchEvent(rootFiber, "topTouchStart", { touches: [t0, t1], changedTouches: [t1] });
|
|
dispatchEvent(rootFiber, "topTouchCancel", { touches: [], changedTouches: [t0, t1] });
|
|
dispatchEvent(rootFiber, "topTouchCancel", { touches: [], changedTouches: [t0, t1] });
|
|
dispatchEvent(inputFiber, "topSelectionChange", { selection: { start: 3, end: 3 } });
|
|
assert.equal(inputGrants, 0, "multi-touch cancel must leave trackedTouchCount at 0");
|
|
assert.deepEqual(
|
|
warnings.filter((w) => w.includes("trackedTouchCount")),
|
|
[],
|
|
);
|
|
});
|
|
}
|
|
|
|
test("patched @mattermost/react-native-paste-input Android PasteTextInput does not claim responder on selection change", () => {
|
|
for (const relPath of [
|
|
"node_modules/@mattermost/react-native-paste-input/src/PasteTextInput.tsx",
|
|
"node_modules/@mattermost/react-native-paste-input/lib/commonjs/PasteTextInput.js",
|
|
"node_modules/@mattermost/react-native-paste-input/lib/module/PasteTextInput.js",
|
|
]) {
|
|
const source = readFileSync(path.resolve(relPath), "utf8");
|
|
assert.equal(
|
|
source.includes("onSelectionChangeShouldSetResponder"),
|
|
false,
|
|
`${relPath} must not set onSelectionChangeShouldSetResponder (matches RN AndroidTextInput)`,
|
|
);
|
|
}
|
|
});
|