Skip to content

Conversation

@dwelle
Copy link
Member

@dwelle dwelle commented May 9, 2024

The main issue was that we were not guaranteeing the text element object got a renewed reference, which then didn't update the scene, not renewing the versionNonce or the elements array, so the renderStaticScene didn't run (also the canvas cache would likely not get invalidated).

@vercel
Copy link

vercel bot commented May 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
excalidraw ✅ Ready (Inspect) Visit Preview May 9, 2024 10:11pm
excalidraw-package-example ✅ Ready (Inspect) Visit Preview May 9, 2024 10:11pm
excalidraw-package-example-with-nextjs ✅ Ready (Inspect) Visit Preview May 9, 2024 10:11pm
1 Ignored Deployment
Name Status Preview Updated (UTC)
docs ⬜️ Ignored (Inspect) May 9, 2024 10:11pm

@github-actions
Copy link

github-actions bot commented May 9, 2024

Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 65.51% (🎯 70%) 51098 / 77992
🔴 Statements 65.51% (🎯 70%) 51098 / 77992
🔴 Functions 66.53% (🎯 68%) 1561 / 2346
🟢 Branches 80.91% (🎯 70%) 6264 / 7741
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/excalidraw/components/App.tsx 69.47% 76.54% 67.87% 69.47% 473-474, 581-590, 689-690, 708-709, 730-790, 793-799, 802-805, 808-884, 887-906, 909-914, 922-932, 934-935, 940-941, 945-947, 961, 968-1229, 1289-1290, 1301-1302, 1330-1332, 1342-1387, 1413, 1423, 1430-1433, 1442-1446, 1477-1478, 1562-1572, 1577-1592, 1596-1643, 1715-1720, 1749-1754, 1757-1787, 1795-1820, 1823-1832, 1835-1947, 1950-1958, 1967-1980, 1983-2009, 2012-2083, 2086-2127, 2179-2180, 2194-2195, 2222-2223, 2227-2228, 2248-2256, 2261-2274, 2280-2281, 2286-2294, 2296-2304, 2316, 2357-2358, 2380-2381, 2388, 2457-2459, 2462-2467, 2472-2473, 2512-2520, 2525-2534, 2572-2573, 2657-2658, 2662, 2665-2666, 2674-2677, 2686-2699, 2705-2708, 2711, 2713-2714, 2721-2722, 2728-2729, 2732-2733, 2741-2742, 2745-2746, 2749-2752, 2763-2771, 2776-2777, 2827-2828, 2842-2848, 2854-2862, 2866-2874, 2878-2879, 2882-2915, 2918-2930, 2941-2942, 2953-2954, 2971-2975, 2979-2982, 2989-2991, 3009-3016, 3019, 3021-3026, 3030-3032, 3053-3054, 3061-3063, 3065-3088, 3114, 3120, 3176-3177, 3194-3196, 3218-3219, 3225-3228, 3234-3315, 3387-3388, 3447, 3457-3475, 3478-3484, 3487-3488, 3494-3507, 3593-3594, 3596-3597, 3602-3604, 3612-3613, 3636-3650, 3655-3674, 3726-3727, 3799, 3808-3809, 3811-3818, 3833-3837, 3848-3849, 3852-3856, 3858-3859, 3861-3864, 3889-3890, 3899-3901, 3903, 3986-3989, 4011-4013, 4023-4024, 4026-4046, 4049-4055, 4072-4075, 4081-4084, 4094-4101, 4141-4145, 4149, 4154-4155, 4160-4164, 4197-4198, 4201-4202, 4205-4206, 4214-4218, 4223-4224, 4230-4240, 4245-4272, 4277-4288, 4355, 4381-4382, 4447-4453, 4536, 4561, 4587-4589, 4656-4657, 4672-4673, 4843-4844, 4847-4848, 4856, 4905-4909, 4960-4967, 4973-5039, 5083, 5132, 5159, 5166-5167, 5176-5179, 5210, 5258-5261, 5264-5270, 5272-5275, 5290-5299, 5302-5303, 5403-5404, 5407, 5409-5414, 5420-5422, 5424, 5433, 5455-5460, 5462-5465, 5469-5470, 5480-5580, 5584-5585, 5600-5601, 5634-5635, 5662-5663, 5696-5723, 5730-5731, 5753-5754, 5773, 5775-5818, 5823-5824, 5826-5827, 5843-5844, 5850-5851, 5855-5858, 5861-5862, 5877-5904, 5912-5913, 5917-5920, 5922-5926, 5944-5948, 5994-5999, 6001-6003, 6019, 6021-6034, 6059-6062, 6106, 6123-6124, 6126-6149, 6164-6165, 6276-6304, 6410-6411, 6431-6432, 6526, 6532-6533, 6556-6575, 6590, 6718, 6740-6778, 6782-6832, 6847, 6856, 6890-6896, 6911-6913, 7055-7058, 7082-7113, 7126, 7128-7136, 7150, 7152-7160, 7167-7170, 7178-7183, 7210-7211, 7216-7218, 7221-7222, 7247-7248, 7279-7280, 7363-7364, 7413-7426, 7492-7495, 7521-7522, 7558-7559, 7572, 7590-7596, 7603-7606, 7629-7635, 7707, 7713, 7728-7735, 7738-7745, 7801, 7878-7879, 7900-7902, 7905, 7919-7943, 8049-8073, 8083-8122, 8135-8136, 8145-8152, 8166-8179, 8192-8199, 8253-8279, 8281-8282, 8356-8357, 8364, 8366-8402, 8431, 8492, 8524-8526, 8551-8556, 8558-8559, 8564-8566, 8569-8589, 8603-8604, 8610-8619, 8624, 8628-8632, 8641-8645, 8648-8653, 8657-8664, 8694, 8696-8700, 8702-8712, 8728-8730, 8741-8749, 8753-8797, 8800-8871, 8879, 8897-8904, 8906-8922, 8937-8959, 8978-8980, 9025-9026, 9140-9144, 9146-9162, 9164-9168, 9180-9181, 9191-9207, 9226-9245, 9247-9248, 9275-9276, 9280-9281, 9291, 9293-9296, 9298-9299, 9339, 9360-9361, 9387, 9390, 9431, 9443-9451, 9468-9469, 9501-9504, 9597-9604, 9630-9631, 9672-9726, 9774-9775, 9784-9787, 9792-9793, 9814-9816, 9818-9822, 9860
packages/excalidraw/components/LayerUI.tsx 83.73% 85.71% 46.42% 83.73% 323, 344-347, 367-372, 417-462, 465-469, 472-488, 495-503, 546-554, 560-563
packages/excalidraw/components/canvases/InteractiveCanvas.tsx 87.82% 100% 100% 87.82% 82-109
packages/excalidraw/components/canvases/StaticCanvas.tsx 98.52% 94.44% 100% 98.52% 36-37
packages/excalidraw/element/mutateElement.ts 100% 100% 100% 100%
packages/excalidraw/element/resizeElements.ts 94.05% 79.62% 100% 94.05% 159, 172-180, 217-218, 268-269, 287-289, 292-293, 295-296, 299-301, 437-438, 489-490, 586-592, 667-668, 711-712, 717, 721, 728-729, 823-824, 836-837, 840-841, 929-938
packages/excalidraw/element/textWysiwyg.tsx 84.71% 79.34% 81.25% 84.71% 63-64, 66-67, 120-121, 308-338, 363-369, 371-373, 377, 484-486, 500-501, 513-518, 549-550, 558-559, 582, 588-616, 633, 635, 638-643, 670-673
packages/excalidraw/scene/Fonts.ts 66.27% 85.71% 100% 66.27% 36-41, 46-60, 74-81
packages/excalidraw/scene/Renderer.ts 98.7% 93.33% 100% 98.7% 82-83
packages/excalidraw/scene/Scene.ts 89.63% 78.26% 92.85% 89.63% 82-83, 97-99, 110-111, 170-171, 234, 250-264, 308-309, 315-316, 333-334, 344-347, 362-365, 380, 388, 406-407
Generated in workflow #2458

Comment on lines +141 to +147
/**
* Random integer regenerated each scene update.
*
* Does not relate to elements versions, it's only a renderer
* cache-invalidation nonce at the moment.
*/
private sceneNonce: number | undefined;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

versionNonce previously, while not inherently bad, could suggest dependency to elements version


informMutation() {
this.versionNonce = randomInteger();
triggerUpdate() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

informMutation() was a bit unclear and incorrect as the it didn't have to relate to mutation, and we generally just care about notifying that an update to the scene happened

);

private onSceneUpdated = () => {
private triggerRender = () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onSceneUpdated() was a bad name for something that only cares about triggering a render

Comment on lines -61 to 54
this.scene.mapElements((element) => {
if (isTextElement(element) && !isBoundToContainer(element)) {
ShapeCache.delete(element);
if (isTextElement(element)) {
didUpdate = true;
return newElementWith(element, {
...refreshTextDimensions(
element,
getContainerElement(element, this.scene.getNonDeletedElementsMap()),
this.scene.getNonDeletedElementsMap(),
),
});
ShapeCache.delete(element);
return newElementWith(element, {}, true);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously we were refreshing only non-containerized text elements because we were afraid (and still are) that reflowing a containerized text could end up changing the container dimensions across different browsers (clients).

Instead, I decided to not refresh text dimensions at all in this function, and just invalidate all text elements (including bound text) so as to force re-render.

@Mrazator but, we have to come up with a strategy for whether or when should we refresh text dimensions. Especially with respect to the coming virgil update which will have slightly different text dimensions. In that case, do we want to refresh dimensions, or is it ok not do it and leave it only after users edit the text later (if at all).


But, I'm actually not sure about this even in the current case, because it may happen the virgil doesn't load for some reason and fall back to a serif font with wildly different dimensions. Should we then refresh dimensions or leave bad bounding boxes? Tough call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on Discord, updating here:

  1. We will keep old Virgil for backwards compatibility.
  2. "it may happen the virgil doesn't load for some reason and fall back to a serif font with wildly different dimensions" - if we don't want to refresh dimensions because we are afraid of breaking container dimensions or the overall layout; then I would also not refresh dimensions at all if we are on a fallback font

@dwelle dwelle merged commit 273ba80 into master May 10, 2024
@dwelle dwelle deleted the dwelle/fix-font-init branch May 10, 2024 14:37
@sentry
Copy link

sentry bot commented May 13, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ RangeError: Maximum call stack size exceeded textPropertiesUpdated(packages/excalidraw/eleme... View Issue
  • ‼️ TypeError: Cannot read properties of undefined (reading 'element') resizeMultipleElements(packages/excalidraw/elem... View Issue
  • ‼️ TypeError: Cannot read properties of undefined (reading 'element') resizeMultipleElements(packages/excalidraw/elem... View Issue
  • ‼️ TypeError: Cannot read properties of undefined (reading 'element') resizeMultipleElements(packages/excalidraw/elem... View Issue
  • ‼️ TypeError: Cannot read properties of undefined (reading 'element') resizeMultipleElements(packages/excalidraw/elem... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants