Skclusive.Material.Component
Skclusive.Material.Component copied to clipboard
Uncaught SyntaxError: Unexpected token '&'
I'm seeing this exception in Console 2x. I identified it is caused by adding <MaterialScripts />
to App.razor file. I guess something is wrong in the ScriptHelpersScript.GetScript
JS string and also in the DomHelpersScript
.
Is it something which can be safely ignored?
is it server rendering mode? could you reproduce this error, running the samples in https://github.com/skclusive/Skclusive.Blazor.Samples? if not could you share repo to reproduce the error?
Yes, this is server rendering mode and I can't reproduce with Skclusive.Blazor.Samples at least not with Skclusive.Blazor.Dashboard.
Here is the example project to reproduce the issue. https://github.com/CsabaStupak/ExcTest
Contains two commits:
- The empty server-side Blazor project
- Minimal change to the project to reproduce the exception.
thanks. i got it.
https://github.com/skclusive/Skclusive.Blazor.Samples/blob/master/Skclusive.Blazor.Dashboard/Dashboard.Server.Host/Startup.cs#L37
we need to have the following options configured. not able to auto detect due to the way server rendering and server pre-rendering works. i guess this needs documentation updates as well.
new MaterialConfigBuilder().WithIsServer(true)
.WithIsPreRendering(false)
.WithResponsive(true)
let me know if this fixes the issue.
I tried to change that line to:
services.TryAddMaterialServices(new MaterialConfigBuilder()
.WithIsServer(true)
.WithIsPreRendering(true)
.Build());
Note WithResponsive
was not available. After this change the given exception was solved however new appeared:
Uncaught SyntaxError: Unexpected end of input
at h (blazor.server.js:8)
at h (blazor.server.js:8)
at Object.s [as insertLogicalChild] (blazor.server.js:8)
at e.insertMarkup (blazor.server.js:8)
at e.insertFrame (blazor.server.js:8)
at e.insertFrameRange (blazor.server.js:8)
at e.insertElement (blazor.server.js:8)
at e.insertFrame (blazor.server.js:8)
at e.applyEdits (blazor.server.js:8)
at e.updateComponent (blazor.server.js:8)
If WithIsPreRendering(FALSE)
then the new exception does not appear, however the original exceptions are back.
i noticed the sample is using server prerendering and there is a caveat in server prerendering mode. so you need to add the below code in startup.cs.
services.AddHttpContextAccessor();
services.AddScoped<IRenderContext>((sp) =>
{
var httpContextAccessor = sp.GetService<IHttpContextAccessor>();
bool? hasStarted = httpContextAccessor?.HttpContext?.Response.HasStarted;
var isPreRendering = !(hasStarted.HasValue && hasStarted.Value);
return new RenderContext(isServer: true, isPreRendering);
});
services.TryAddMaterialServices(new MaterialConfigBuilder().WithIsServer(true).WithIsPreRendering(true).Build());
i have verified it with your sample code. hope this helps.
Work like a charm. Thank you :-)
i guess documentation needs to be updated. keeping it open.
Yep, please add it to the docs. I also tripped over this
in the dashboard samples in the _Host file , the code for the "blazor-error-ui" div is commented out with the Todo comment
TODO: need to investigate why visible on load
so I guess the issue is still there
@Sammy-AZ yes. that is separate issue. just need to update the site.css with default blazor styles for error-ui. will update. thanks.