Can Of Code

Removing FontAwesome CSS from footer when using WPBakery

On a recent project I had already included FontAwesome using their Kit setup where the css / webfonts are loaded by their script. The issue I faced was that because I was using WPBakery I was then including FontAwesome twice.

To remove the enqueued FontAwesome css files I added the following to the themes functions.php


add_action('wp_enqueue_scripts', 'canofcode_dequeue_font_awesome_style', 11);
function canofcode_dequeue_font_awesome_style() {
    wp_deregister_style( 'vc_font_awesome_5_shims' );
    wp_dequeue_style( 'vc_font_awesome_5_shims' );
    wp_deregister_style( 'vc_font_awesome_5' );
    wp_dequeue_style( 'vc_font_awesome_5' );
}

 

I found that it doesn’t effect the loading of FontAwesome when editing the page in the backend editor. I struggled to find something like this when Googling so hope it helps.

Posted in WordPress | Tagged | Leave a comment

Fixed Crashing of ATI Radeon 5600xt drivers on Windows

I’ve been lucky enough to look at replacing my now 5-6 year old laptop which has become to churn at that thought of Photoshop or Visual Studio. I have not built a PC in a long time and was a little daunted at first but not too much has changed. So I order everything I needed and got set on putting it all together.

  • Processor: Ryzen 7 3800X
  • MSI Radeon RX5600XT
  • 32 GB (2 x 16gb) 2666 DDR4 RAM
  • MSI Tomahawk Motherboard

All went well everything clicked into place, installed Windows, installed some games, updates and all the software I need. Then when I got into playing a game, the screen would go blank, then a handy little message would inform me that the Graphic drivers had gone wobbly and you should tell someone about it.

Some of the errors I was getting:

  • Event viewer would show: LiveKernelEvent 141 Error
  • the errors related to: LKD_0x141_Tdr:6_IMAGE_amdkmdag.sys.
ATI Radeon RX5600XT wasn't the problem

The internet will know!

I headed to Google to find a significant number of forum posts of people having the same issue with the same graphics card and lots of people were pointing to the drivers being the issue. Following the advice I tried the following:

  • Propped up the graphics card with some Lego! (Some were suggesting the card was so heavy it was sliding out the PCIe connector.
  • Installed many different combinations of Drivers from the latest to one from months ago
  • Swapping around the power cables
  • Questioning everything I bought, assuming I got something wrong somewhere.
  • Ran a memory test, passed with flying colours.

I was starting to get disheartened now, perhaps I should have stuck with a laptop and let the experts make the computers. Did I just buy a bad graphics card? However I found it just too hard to give up debugging this so I decided to just take one of the sticks of RAM out on a whim really.

BINGO!

No more crashes. Why RAM was causing the display drivers to crash I just didn’t understand. I wasn’t happy with this diagnoses because maybe it was just a coincidence? so I took out all the RAM and then put in the crashing stick and the crashing was back.

Must be the crashing stick! I was hoping that MemTest86 will tell me for certain but after running it over 4 passes there were no errors.  So its still sort of a mystery whenever that stick of RAM is in the PC, it will continually crash in games. I have returned the RAM and hoping that the replacement will be fine (It was although I went for a different brand and a faster speed 3200). Hopefully this will be useful for someone having trouble with the blank / black screen when playing games with the 5600XT. If anyone has any theories on how the RAM could pass Memory Tests but still be faulty let me know! And for that matter, why bad RAM crashes the graphics drivers exclusively?

Posted in Gaming | Tagged , | Leave a comment

Blazor WebAssembly .NET5 – First look and some gotchas

What is Blazor WebAssembly?

Blazor can be described most simply as a frontend framework like Angular but instead of JavaScript or TypeScript we get to use C# (that is where WebAssembly comes into play). Because we are using C# for the frontend we can share some code between the front and back and lets face it, use a language that we are comfortable with.

There are some drawbacks to such as the initially load time is likely to be slower because the client has to download the assembly before they can get started.

There is a Server based model for Blazor which does not rely on WebAssembly and instead does most of the processing server side. you can get a much better explanation of it here.

Identity gets complex

Like any client sides technology, handling authentication always becomes a little more complex than using a cookie based approach. This has been something that I have always felt held me back from using SPAs in the past. You have to  investigate methods such as OpenId to exchange tokens. This is not anything new for say mobile app development but it is more complex to get your head around then the cookie based. The tooling around OpenId is dependant on third party packages such as IdentityServer. Would be nice if this part of the framework but there is plenty of support and documentation.

Helpful Blazor Project Template

The Visual Studio Blazor template thankfully comes with IdentityServer already setup which saves you a lot of time learning. Its also runnable from the start, running your backend server in debug while also running the client. One thing I wish the template had setup was an example of authenticated POST of data and linking that data to the logged in user.

Trouble getting the Logging in User in the Controller

One early issue I had was getting the current logged in user object using the User Manager. Running say:

var user = await _userManager.GetUserAsync(User);

would always return null even though User had a valid identity. Turns out this is related to GetUserAsync looking at the wrong claim to get the users Id . You can therefore use something like below to get the users Id then look up the user using the DatabaseContext

var id = User.FindFirstValue(ClaimTypes.NameIdentifier);
return _context.Users.FirstOrDefault(x => x.Id == id);

What is the upfront download / loadtime?

As a debug build with the Blazor template we are looking at 9.6Mb download on first load but they do fire out a console log message promising it will be smaller when you publish. So after a publish we are still looking at 3.7mb weight which admittedly not that bad considering its including some bootstrap styling and all the logic and should only be at the initial visit. As a really unscientific measure the initial load times even with the resources cached takes 10-15 seconds which would be impractical for a simple website but I suspect it would be understandable for a complex application that users would expect some load time.

The Client can be hosted anywhere?

Yes but you do need some sort of server to help with routing for example if you go to test.local/things then you need a server to route /things to the index.html. I was able to get the Client running on a local Apache LAMP setup using the configuration discussed here 

I did a separate post: blazor webassembly on a different host to the server which explains the process I went through to setup the Client on a different host to the server.

Posted in Blazor | Leave a comment