Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught SyntaxError: Unexpected token '&' #36

Open
CsabaStupak opened this issue May 23, 2020 · 10 comments
Open

Uncaught SyntaxError: Unexpected token '&' #36

CsabaStupak opened this issue May 23, 2020 · 10 comments
Assignees

Comments

@CsabaStupak
Copy link

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?

@skclusive
Copy link
Owner

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?

@CsabaStupak
Copy link
Author

CsabaStupak commented May 23, 2020

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.

@skclusive
Copy link
Owner

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.

@CsabaStupak
Copy link
Author

CsabaStupak commented May 24, 2020

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.

@skclusive
Copy link
Owner

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.

@CsabaStupak
Copy link
Author

Work like a charm. Thank you :-)

@skclusive skclusive self-assigned this May 27, 2020
@skclusive
Copy link
Owner

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

@henon
Copy link
Contributor

henon commented Jun 19, 2020

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

@Sammy-AZ
Copy link

Sammy-AZ commented Nov 18, 2020

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

@skclusive
Copy link
Owner

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

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

No branches or pull requests

4 participants