Skclusive.Material.Component icon indicating copy to clipboard operation
Skclusive.Material.Component copied to clipboard

Uncaught SyntaxError: Unexpected token '&'

Open CsabaStupak opened this issue 4 years ago • 10 comments

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?

CsabaStupak avatar May 23 '20 05:05 CsabaStupak

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?

skclusive avatar May 23 '20 06:05 skclusive

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.

CsabaStupak avatar May 23 '20 08:05 CsabaStupak

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.

skclusive avatar May 23 '20 16:05 skclusive

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.

CsabaStupak avatar May 24 '20 05:05 CsabaStupak

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.

skclusive avatar May 27 '20 00:05 skclusive

Work like a charm. Thank you :-)

CsabaStupak avatar May 27 '20 08:05 CsabaStupak

i guess documentation needs to be updated. keeping it open.

skclusive avatar May 27 '20 12:05 skclusive

Yep, please add it to the docs. I also tripped over this

henon avatar Jun 19 '20 20:06 henon

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 avatar Nov 18 '20 14:11 Sammy-AZ

@Sammy-AZ yes. that is separate issue. just need to update the site.css with default blazor styles for error-ui. will update. thanks.

skclusive avatar Nov 19 '20 04:11 skclusive