Comments (10)
This is where my knowledge of Blazor's RenderTree and lifecycle fails me. This is just my guess, but I think what may be happening is:
-
DOM is built on the server
-
halfmoon.js is loaded
-
halfmoon.pageWrapper
is set (it's set correctly and references the element that containsclass="page-wrapper"
) -
Blazor builds the render tree
-
Blazor sends the render tree and required files, images, etc to the client through SignalR connection
-
Blazor.server.js manipulates the DOM to replicate the render tree
-
halfmoon.toggleSidebar
is called (sidebar is currently shown) -
halfmoon.js adds the
data-sidebar-hidden
attribute to thepageWrapper
element but this is the element from the DOM that is initially built in step 1. -
No changes happen to the
<div class="page-wrapper"></div>
element in the DOM because it was rebuilt from the render tree through blazor.server.js and is actually a different element now than the one is step 1-3
By adding the function in my previous comment and calling it after step 6, the element stored in halfmoon.pageWrapper
is updated to the element currently in the DOM.
Now, I may be a little off with that guess or way off. I'm not sure. The whole point of Blazor is being able to manipulate the DOM through C# and so the framework handles the DOM behind the scenes. I've never had to deal with a problem like this.
from halfmoon.
@RoseberryPi Thank you for the details. I am not opposed to adding the method you mentioned, but I would definitely want more validation as to how Blazor actually works under the hood.
from halfmoon.
I worked around this by calling the Halfmoon js within _Host.cshtml
immediately before the blazor js instead of placing it in the <head>
. I'm pulling it in from a library so your src
url may differ.
<body>
<app>
<component type="typeof(App)" render-mode="ServerPrerendered" />
</app>
<script type="text/javascript" src="_content/Halfmoon.Blazor/js/halfmoon.js"></script>
<script src="_framework/blazor.server.js"></script>
</body>
from halfmoon.
Unfortunately, I am not familiar with Blazor. Could you explain why the solution you proposed actually fixes the problem? Does Blazor generate the DOM in a novel way or something? And it is not the ideal fix, because the existing code is meant to work with virtual DOMs, ala, Vue, React, etc.
from halfmoon.
I'm still not 100% clear on how Blazor handles the DOM so hopefully I can explain well enough.
To put it simply, halfmoon.pageWrapper
and halfmoon.stickyAlerts
are set before the DOM is finished rendering (as far as Blazor is concerned).
halfmoonOnDOMContentLoaded
is called but since those properties have been set, they're not updated.
So for example, when halfmoon.toggleSidebar
is called it updates halfmoon.pageWrapper
but it's simply not the same element that is actually in the DOM.
I'm not too familiar with javascript and the DOM (and I don't use Angular, Vue, React, etc.) so maybe I'm not explaining well but regardless, it's an issue with the way Blazor handles DOM manipulation.
Perhaps adding another javascript function that will force those properties to be updated would be the better solution. You keep things the same but Blazor devs still have a work around. Something as simple as:
function forceUpdateDOMContent() {
halfmoon.pageWrapper = document.getElementsByClassName("page-wrapper")[0];
halfmoon.stickyAlerts = document.getElementsByClassName("sticky-alerts")[0];
}
Blazor devs would just need to call this through JSInterop after render (using the OnAfterRenderAsync
method in razor components) to reset those properties.
Here's some documentation to get more info on Blazor.
Blazor Lifecycle
Blazor JSInterop
Article on Blazor's RenderTree
I can do some more debugging later this week when I'm working on the project again (you can see it here, just a side project).
from halfmoon.
That's interesting. What are they set to, if not the DOM elements? In any case, I have marked this, and I would appreciate input from anyone who is more familiar with Blazor.
from halfmoon.
@DouglasRiddle Thank you for this solution.
@RoseberryPi Can you please confirm if this works for you or not?
from halfmoon.
<script src="./js/halfmoon.min.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
When I tried the code sequence like above. Drak Mode perfectly works on blazorwasm (client-side). But not the sidebar. Still digging into it.
from halfmoon.
Just to chip in here, this is also a problem in Angular - making the change proposed by the OP fixes the issue there as well.
The issue I was seeing was that toggling the sidebar was not updating the data-sidebar-hidden
attribute on the pageWrapper
even though the method was executing successfully.
from halfmoon.
It is working on Blazor wasm. If it works on Blazor wasm, I believe it already works on Server-side Blazor too.
First Import halfmoon.js before blazor.webssembly.js.
<script src="./js/halfmoon.min.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
Second, in index.html inside the app tag use classes as follows.
<app class="page-wrapper with-navbar with-sidebar"
data-sidebar-type="overlayed-sm-and-down">Loading...</app>
So, the working code will look like.
<body class="with-custom-webkit-scrollbars with-custom-css-scrollbars"
data-sidebar-shortcut-enabled="true"
data-dm-shortcut-enabled="true">
<!-- Sticky alerts (toasts), empty container -->
<app class="page-wrapper with-navbar with-sidebar"
data-sidebar-type="overlayed-sm-and-down">Loading...</app>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="./js/halfmoon.min.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
</body>
from halfmoon.
Related Issues (20)
- Website Down HOT 1
- Modal close event HOT 3
- Select does not work properly in mobile
- set color mode instead of toggle js HOT 2
- [Feature request] Put label before switch
- Sidebar, darkmode and modals are not automatically toggled as expected. HOT 5
- halfmoon doesn't support rtl? HOT 2
- require problem while using with sveltekit. HOT 1
- this.stickyAlerts is undefined HOT 1
- Will the project continue? HOT 2
- Text centering inside buttons
- Default sidebar with small screen results in offscreen content HOT 2
- Halfmoon documentation isn't available anymore HOT 37
- is this project dead? HOT 27
- Version update messed up page layout completely HOT 2
- Provide CSS only alternatives using Dialog and Popover API.
- CSS only form validation HOT 1
- Website is down HOT 1
- Typo in dropdowns page code snippet
- input type = date, just use this that way?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from halfmoon.