Skip to content

Commit ee8e3c8

Browse files
committed
feat(infra): prevent invariant globalization in server web because of client web publish settings #11367 (#11368)
1 parent 72bafdd commit ee8e3c8

File tree

6 files changed

+43
-2
lines changed

6 files changed

+43
-2
lines changed

.github/workflows/admin-sample.cd.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ jobs:
127127
- name: Configure bswup # The adminpanel.bitplatform.dev lacks pre-rendering functionality, but the configuration below enables lazy loading of files when feasible. True offline support is not expected for this demo.
128128
run: |
129129
sed -i "s/\/\/ self.prerenderMode = 'initial'/self.prerenderMode = 'initial'/g" AdminPanel/src/Client/AdminPanel.Client.Web/wwwroot/service-worker.published.js
130+
131+
- name: Enable WebInteropApp route
132+
run: |
133+
# Uncomment the Route attribute for WebInteropApp component as noted in the WebInteropApp.razor's comments
134+
sed -i 's/@\* @attribute \[Route("web-interop-app")\] \*@/@attribute [Route("web-interop-app")]/' AdminPanel/src/Client/AdminPanel.Client.Core/Components/WebInteropApp.razor
130135
131136
- name: Generate CSS/JS files
132137
run: dotnet build AdminPanel/src/Client/AdminPanel.Client.Core/AdminPanel.Client.Core.csproj -t:BeforeBuildTasks -p:Version="${{ vars.APP_VERSION}}" --no-restore -c Release

.github/workflows/todo-sample.cd.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ jobs:
150150

151151
- name: Install wasm
152152
run: cd src && dotnet workload install wasm-tools
153+
154+
- name: Enable WebInteropApp route
155+
run: |
156+
# Uncomment the Route attribute for WebInteropApp component as noted in the WebInteropApp.razor's comments
157+
sed -i 's/@\* @attribute \[Route("web-interop-app")\] \*@/@attribute [Route("web-interop-app")]/' TodoSample/src/Client/TodoSample.Client.Core/Components/WebInteropApp.razor
153158
154159
- name: Generate CSS/JS files
155160
run: dotnet build TodoSample/src/Client/TodoSample.Client.Core/TodoSample.Client.Core.csproj -t:BeforeBuildTasks -p:Version="${{ vars.APP_VERSION}}" --no-restore -c Release
@@ -197,6 +202,11 @@ jobs:
197202

198203
- name: Install wasm
199204
run: cd src && dotnet workload install wasm-tools
205+
206+
- name: Enable WebInteropApp route
207+
run: |
208+
# Uncomment the Route attribute for WebInteropApp component as noted in the WebInteropApp.razor's comments
209+
sed -i 's/@\* @attribute \[Route("web-interop-app")\] \*@/@attribute [Route("web-interop-app")]/' TodoSample/src/Client/TodoSample.Client.Core/Components/WebInteropApp.razor
200210
201211
- name: Generate CSS/JS files
202212
run: dotnet build TodoSample/src/Client/TodoSample.Client.Core/TodoSample.Client.Core.csproj -t:BeforeBuildTasks -p:Version="${{ vars.APP_VERSION}}" -p:InvariantGlobalization=true --no-restore -c Release
@@ -244,6 +254,11 @@ jobs:
244254

245255
- name: Install wasm
246256
run: cd src && dotnet workload install wasm-tools
257+
258+
- name: Enable WebInteropApp route
259+
run: |
260+
# Uncomment the Route attribute for WebInteropApp component as noted in the WebInteropApp.razor's comments
261+
sed -i 's/@\* @attribute \[Route("web-interop-app")\] \*@/@attribute [Route("web-interop-app")]/' TodoSample/src/Client/TodoSample.Client.Core/Components/WebInteropApp.razor
247262
248263
- name: Generate CSS/JS files
249264
run: dotnet build TodoSample/src/Client/TodoSample.Client.Core/TodoSample.Client.Core.csproj -t:BeforeBuildTasks -p:Version="${{ vars.APP_VERSION}}" --no-restore -c Release

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/WebInteropApp.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ Additionally, in a Web Browser, if Social Sign-in is performed in a Popup or a n
1111
state and avoid restarting Blazor upon returning from Social Sign-in, the Popup should redirect back to WebInteropApp
1212
after authentication. Using app.js, it can notify the main Window via window.opener.postMessage({ key: 'PUBLISH_MESSAGE', ... }),
1313
allowing the main Window to resume its operations.
14+
15+
When publishing Client.Web (BlazorWebAssembly Standalone) and Server.Api, there won't be any WebInteropAppEndpoint,
16+
in this case, uncomment the Route attribute below to make this component accessible via /web-interop-app route.
1417
*@
18+
@* @attribute [Route("web-interop-app")] *@
1519

1620
@code {
1721
[Inject] public IStringLocalizer<AppStrings> Localizer { get; set; } = default!;

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private async Task<IActionResult> UploadAttachment(Guid attachmentId, Attachment
228228

229229
var response = await chatClient.GetResponseAsync<AIImageReviewResponse>(
230230
messages: [
231-
new ChatMessage(ChatRole.System, "Return a JSON object with two properties: 'isCar' (boolean, true if the image contains a car, false otherwise) and 'alt' (string, describing the image content). Do not include any other properties or text."),
231+
new ChatMessage(ChatRole.System, "Return a JSON object with two properties: 'isCar' (boolean, true if the image contains a car, false otherwise) and 'alt' (string, describing the image content, focusing on the car). Do not include any other properties or text."),
232232
new ChatMessage(ChatRole.User, "Analyze this image.")
233233
{
234234
Contents = [new DataContent(imageBytes, "image/webp")]

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/SignalR/AppHub.Chatbot.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ async Task HandleIncomingMessage(string incomingMessage, CancellationToken messa
168168
new(ChatRole.System, supportSystemPrompt),
169169
new(ChatRole.User, incomingMessage),
170170
new(ChatRole.Assistant, assistantResponse.ToString()),
171-
new(ChatRole.User, @"Return up to 3 relevant follow-up suggestions that help users discover related topics and continue the conversation naturally based on user's query in JSON object containing string[] named FollowUpSuggestions."),],
171+
new(ChatRole.User, @"Return up to 3 relevant follow-up suggestions that help users discover related topics and continue the conversation naturally based on user's query in JSON object containing string[] named FollowUpSuggestions.
172+
Only suggest follow-up questions that are within the assistant's scope and knowledge.
173+
Do not suggest questions that require access to data or functionality that is unavailable or out of scope for this assistant.
174+
Avoid suggesting questions that the assistant would not be able to answer."),],
172175
chatOptions, cancellationToken: cancellationToken);
173176

174177
await channel.Writer.WriteAsync(JsonSerializer.Serialize(followUpItems.Result), cancellationToken);

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Web/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public static partial class Program
1111
{
1212
public static async Task Main(string[] args)
1313
{
14+
ConfigureGlobalization();
15+
1416
var builder = WebApplication.CreateBuilder(options: new()
1517
{
1618
Args = args,
@@ -69,4 +71,16 @@ private static void LogException(object? error, string reportedBy, WebApplicatio
6971
_ = Console.Error.WriteLineAsync(error?.ToString() ?? "Unknown error");
7072
}
7173
}
74+
75+
/// <summary>
76+
/// You might consider setting `InvariantGlobalization` to `true` when publishing Server.Web and Blazor WebAssembly simultaneously,
77+
/// as this can reduce the website's size. However, doing so would also make the server project culture-invariant, which offers minimal benefit
78+
/// and could potentially cause issues.The following environment variable allows you to maintain server culture support
79+
/// while reducing the client's size through invariant culture.
80+
/// https://learn.microsoft.com/en-us/dotnet/core/runtime-config/globalization#invariant-mode
81+
/// </summary>
82+
private static void ConfigureGlobalization()
83+
{
84+
Environment.SetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "false");
85+
}
7286
}

0 commit comments

Comments
 (0)