Skip to content

Commit 062237e

Browse files
author
msftbot[bot]
authored
Merge pull request #27173 from dotnet-maestro-bot/merge/release/5.0-to-master
[automated] Merge branch 'release/5.0' => 'master'
2 parents ad34c65 + 6b557d8 commit 062237e

File tree

9 files changed

+84
-15
lines changed

9 files changed

+84
-15
lines changed

NuGet.config

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<packageSources>
44
<clear />
55
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
6-
<add key="darc-pub-dotnet-runtime-2d8e19f" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-2d8e19f1/nuget/v3/index.json" />
7-
<add key="darc-pub-dotnet-efcore-69c4c9d" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-efcore-69c4c9d1/nuget/v3/index.json" />
6+
<add key="darc-pub-dotnet-runtime-cf258a1-1" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-cf258a14-1/nuget/v3/index.json" />
7+
<add key="darc-pub-dotnet-efcore-73566d1" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-efcore-73566d1f/nuget/v3/index.json" />
88
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
99
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
1010
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />

src/Components/Web.JS/dist/Release/blazor.server.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.webassembly.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/src/InputFile.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ async function readFileData(elem: InputElement, fileId: number, startOffset: num
112112
function readFileDataSharedMemory(readRequest: any): number {
113113
const inputFileElementReferenceId = monoPlatform.readStringField(readRequest, 0);
114114
const inputFileElement = document.querySelector(`[_bl_${inputFileElementReferenceId}]`);
115-
const fileId = monoPlatform.readInt32Field(readRequest, 4);
116-
const sourceOffset = monoPlatform.readUint64Field(readRequest, 8);
117-
const destination = monoPlatform.readInt32Field(readRequest, 16) as unknown as System_Array<number>;
118-
const destinationOffset = monoPlatform.readInt32Field(readRequest, 20);
119-
const maxBytes = monoPlatform.readInt32Field(readRequest, 24);
115+
const fileId = monoPlatform.readInt32Field(readRequest, 8);
116+
const sourceOffset = monoPlatform.readUint64Field(readRequest, 12);
117+
const destination = monoPlatform.readInt32Field(readRequest, 24) as unknown as System_Array<number>;
118+
const destinationOffset = monoPlatform.readInt32Field(readRequest, 32);
119+
const maxBytes = monoPlatform.readInt32Field(readRequest, 36);
120120

121121
const sourceArrayBuffer = getFileById(inputFileElement as InputElement, fileId).arrayBuffer as ArrayBuffer;
122122
const bytesToRead = Math.min(maxBytes, sourceArrayBuffer.byteLength - sourceOffset);

src/Components/Web/src/Forms/InputFile/ReadRequest.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@ namespace Microsoft.AspNetCore.Components.Forms
88
[StructLayout(LayoutKind.Explicit)]
99
internal struct ReadRequest
1010
{
11+
// Even though this type is only intended for use on WebAssembly, make it able to
12+
// load on 64-bit runtimes by allowing 8 bytes for each reference-typed field.
13+
1114
[FieldOffset(0)]
1215
public string InputFileElementReferenceId;
1316

14-
[FieldOffset(4)]
17+
[FieldOffset(8)]
1518
public int FileId;
1619

17-
[FieldOffset(8)]
20+
[FieldOffset(12)]
1821
public long SourceOffset;
1922

20-
[FieldOffset(16)]
23+
[FieldOffset(24)]
2124
public byte[] Destination;
2225

23-
[FieldOffset(20)]
26+
[FieldOffset(32)]
2427
public int DestinationOffset;
2528

26-
[FieldOffset(24)]
29+
[FieldOffset(36)]
2730
public int MaxBytes;
2831
}
2932
}

src/Components/Web/src/Virtualization/Virtualize.cs

+18
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,15 @@ void IVirtualizeJsCallbacks.OnBeforeSpacerVisible(float spacerSize, float spacer
253253
{
254254
CalcualteItemDistribution(spacerSize, spacerSeparation, containerSize, out var itemsBefore, out var visibleItemCapacity);
255255

256+
// Since we know the before spacer is now visible, we absolutely have to slide the window up
257+
// by at least one element. If we're not doing that, the previous item size info we had must
258+
// have been wrong, so just move along by one in that case to trigger an update and apply the
259+
// new size info.
260+
if (itemsBefore == _itemsBefore && itemsBefore > 0)
261+
{
262+
itemsBefore--;
263+
}
264+
256265
UpdateItemDistribution(itemsBefore, visibleItemCapacity);
257266
}
258267

@@ -262,6 +271,15 @@ void IVirtualizeJsCallbacks.OnAfterSpacerVisible(float spacerSize, float spacerS
262271

263272
var itemsBefore = Math.Max(0, _itemCount - itemsAfter - visibleItemCapacity);
264273

274+
// Since we know the after spacer is now visible, we absolutely have to slide the window down
275+
// by at least one element. If we're not doing that, the previous item size info we had must
276+
// have been wrong, so just move along by one in that case to trigger an update and apply the
277+
// new size info.
278+
if (itemsBefore == _itemsBefore && itemsBefore < _itemCount - visibleItemCapacity)
279+
{
280+
itemsBefore++;
281+
}
282+
265283
UpdateItemDistribution(itemsBefore, visibleItemCapacity);
266284
}
267285

src/Components/Web/test/Forms/InputFileChangeEventArgsTest.cs

+11
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,16 @@ public void GetMultipleFiles_ThrowsIfTooManyFiles()
6565
var ex = Assert.Throws<InvalidOperationException>(() => instance.GetMultipleFiles(1));
6666
Assert.Equal($"The maximum number of files accepted is 1, but 2 were supplied.", ex.Message);
6767
}
68+
69+
[Fact]
70+
public void ReadRequestTypeCanBeLoaded()
71+
{
72+
// Represents https://github.com/dotnet/aspnetcore/issues/26882
73+
// Even though the ReadRequest type is only ever used on WebAssembly, developers might
74+
// do something that causes the type to be loaded on other environments, for example
75+
// using reflection. It's just a DTO with no behaviors so there's nothing to test
76+
// except that loading the type doesn't trigger an exception.
77+
GC.KeepAlive(new ReadRequest());
78+
}
6879
}
6980
}

src/Components/test/E2ETest/Tests/VirtualizationTest.cs

+28
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Linq;
5+
using System.Threading.Tasks;
56
using BasicTestApp;
67
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
78
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
@@ -216,6 +217,33 @@ public void CanUseViewportAsContainer()
216217
Browser.NotEqual(expectedInitialSpacerStyle, () => topSpacer.GetAttribute("style"));
217218
}
218219

220+
[Fact]
221+
public async Task ToleratesIncorrectItemSize()
222+
{
223+
Browser.MountTestComponent<VirtualizationComponent>();
224+
var topSpacer = Browser.Exists(By.Id("incorrect-size-container")).FindElement(By.TagName("div"));
225+
var expectedInitialSpacerStyle = "height: 0px;";
226+
227+
// Wait until items have been rendered.
228+
Browser.True(() => GetItemCount() > 0);
229+
Browser.Equal(expectedInitialSpacerStyle, () => topSpacer.GetAttribute("style"));
230+
231+
// Scroll slowly, in increments of 50px at a time. At one point this would trigger a bug
232+
// due to the incorrect item size, whereby it would not realise it's necessary to show more
233+
// items because the first time the spacer became visible, the size calculation said that
234+
// we're already showing all the items we need to show.
235+
for (var pos = 0; pos < 1000; pos += 50)
236+
{
237+
Browser.ExecuteJavaScript($"document.getElementById('incorrect-size-container').scrollTop = {pos};");
238+
await Task.Delay(200);
239+
}
240+
241+
// Validate that the top spacer did change
242+
Browser.NotEqual(expectedInitialSpacerStyle, () => topSpacer.GetAttribute("style"));
243+
244+
int GetItemCount() => Browser.FindElements(By.ClassName("incorrect-size-item")).Count;
245+
}
246+
219247
[Fact]
220248
public void CanMutateDataInPlace_Sync()
221249
{

src/Components/test/testassets/BasicTestApp/VirtualizationComponent.razor

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
</div>
2929
</p>
3030

31+
<p>
32+
Slightly incorrect item size:<br />
33+
<div id="incorrect-size-container" style="background-color: #eee; height: 500px; overflow-y: auto">
34+
<Virtualize Items="@fixedItems" ItemSize="50">
35+
<div @key="context" class="incorrect-size-item" style="height: 49px; background-color: rgb(@((context % 2) * 255), @((1-(context % 2)) * 255), 255);">Item @context</div>
36+
</Virtualize>
37+
</div>
38+
</p>
39+
3140
<p id="viewport-as-root">
3241
Viewport as root:<br />
3342
<Virtualize Items="@fixedItems" ItemSize="itemSize">

0 commit comments

Comments
 (0)