-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
[Live] Add data-error
attribute + fix loading behaviour on error
#1916
base: 2.x
Are you sure you want to change the base?
Conversation
Thank you very much @YummYume ! I'll review in depth during week-end A first comment though: i'm not sure we should expose the same API / possibilities, as such errors "should not" happen and we don't want to maintain/document too many things if they are not used. So maybe could we select only one or two methods ? What do you think ? Regarding the attribute, (The documentation seems great, i think i'd inverse the 2 sections and start with the "what" before the "how") |
'loading.state:started': (element: HTMLElement, request: BackendRequest) => MaybePromise; | ||
'loading.state:finished': (element: HTMLElement) => MaybePromise; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me some time to understand this ... as you have some CS changes mixed in here :)
Could you -if you have time- open a PR just for this "bug fix" ?
I know it's only TS and not really a bug, but people will probably see these values in their IDE... and i'd really like them to see the good ones instead 😅
And also to ensure we merge the fix asap .... because this one will depend on the path we choose to take :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do! I just added the typing to the hooks to not have to remember the event names and having a better DX, but I was wondering why my event wasn't firing... Only to find out there was a typo in the typing 😅
@smnandre Thanks for the feedback! 😄 By that, you mean only allowing the And I thought the same about the |
7f8b505
to
ae2cf69
Compare
data-error
attribute + fix loading behaviour on errordata-error
attribute + fix loading behaviour on error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wohaaaa! Thanks @YummYume for your PR! It's so cool! I love the path taking here!
I noticed that the data-live-error="addClass(text-red-500)" does not work. I didn't dig to see why but here is my template :
<div {{ attributes }}>
<p data-live-error="addClass(text-red-500)">Hello</p>
<button
data-action="live#action"
data-live-action-param="error"
>
Throw
</button>
<span data-live-error="show">An error occurred ! Please try again.</span>
</div>
the class text-red-500 is not added but the span is well added. Maybe you could have a clue.
I think we should disable the pop up we the error by default in production, and actually even in dev ? Do you think this is still needed since we have the request in the profiler ?
Thanks @WebMamba ! I just tried it, and it does work for me, the class is added on the element with the attribute. Is it maybe just that the class does nothing because you're not using Tailwind ? And about the error modal, I'm not sure, I think it's still a great and more direct debugging tool than the profiler. But for more in depth debugging, it's of course not ideal. |
This PR was merged into the 2.x branch. Discussion ---------- [Live] Fix typing for loading hooks + HookManager | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | | License | MIT See #1916 (comment) for context Fixes the typo on the loading hooks and add the hook typing to the `HookManager` (was forgotten in my first pr) Commits ------- 9428547 Fix typing for loading hooks + HookManager
This PR was merged into the 2.x branch. Discussion ---------- [Live] Fix typing for loading hooks + HookManager | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | | License | MIT See symfony/ux#1916 (comment) for context Fixes the typo on the loading hooks and add the hook typing to the `HookManager` (was forgotten in my first pr) Commits ------- 94285477 Fix typing for loading hooks + HookManager
Wherer are we on this one ? are you blocked by something ? Can i help you in any way @YummYume ? |
Hey @smnandre ! I'll work on resolving the conflicts ASAP but other than that, no, I think it was all good ! If there are any suggestions or changes wanted to the current behavior, I'm all ears. |
…tes removal on error
A couple of questions / comments, but to me we're almost there 😄 I'm still a bit doubtfull we need all the modifier and/or should maybe refactor the code avoid doubling the code with the existing ones, but this (refactor the existing) could be done in a later step / PR. Do we really need the showError method for instance ? I mean do you think all the JS code can be simplified, more "direct" ? (genuine question) Also, i'm not a big fan of the added CSS and would love for use to remove it entirely in future versions, so is there any way to handle this feature without adding CSS ? |
1ae59fe
to
81f01c3
Compare
Rebase is done. Some of the code could perhaps be unified, but there was already a big part done (all the parsing is already shared between the loading and error plugins). I also made sure not to include too complex behaviors, such as targeting a specific action (which makes no sense here) or using modifiers with the attributes. So with all that, I don't see a reason why not include them ? At least it stays consistent with the loading plugin. I did my best to make the plugin readable and easy to understand for any further modification, especially since this PR is technically only the first part of our long discussion on how to properly handle errors. I agree with you for the CSS. On top of that, it doesn't always work. There can still a short window where you can actually see the element, until this style is loaded. Which is why (and I added this part in the doc as well), I always add my own |
@@ -60,7 +60,7 @@ | |||
} | |||
|
|||
.dropzone-preview-button::before { | |||
content: '×'; | |||
content: "×"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this :)
We'll make the change in another small PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never made that change, I think that's just the linter ?
@@ -1 +1 @@ | |||
.dropzone-container{position:relative;display:flex;min-height:100px;border:2px dashed #bbb;align-items:center;padding:20px 10px}.dropzone-input{position:absolute;display:block;top:0;left:0;width:100%;height:100%;opacity:0;cursor:pointer;z-index:1}.dropzone-preview{display:flex;align-items:center;max-width:100%}.dropzone-preview-image{flex-basis:0;min-width:50px;max-width:50px;height:50px;margin-right:10px;background-size:contain;background-position:50% 50%;background-repeat:no-repeat}.dropzone-preview-filename{word-wrap:anywhere}.dropzone-preview-button{position:absolute;top:0;right:0;z-index:1;border:none;margin:0;padding:0;width:auto;overflow:visible;background:0 0;color:inherit;font:inherit;line-height:normal;-webkit-font-smoothing:inherit;-moz-osx-font-smoothing:inherit;-webkit-appearance:none}.dropzone-preview-button::before{content:'×';padding:3px 7px;cursor:pointer}.dropzone-placeholder{flex-grow:1;text-align:center;color:#999} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(same)
private showElement(element: HTMLElement | SVGElement) { | ||
element.style.display = 'revert'; | ||
} | ||
|
||
private hideElement(element: HTMLElement | SVGElement) { | ||
element.style.display = 'none'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the dev used style="display: flex"
on element, what will happens when calling showElement
?
Can we add/remove a custom CSS class instead, like data-live-hidden
? It would be safer than manipulating element.style.display
IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that sadly doesn't work, but this is a current issue with the data-loading
attribute as well (see #102).
A simple workaround is to do something like class="hidden" data-live-error="addClass(flex) removeClass(hidden)"
instead. That will work.
I also don't think adding more custom CSS would be a good idea, as discussed above, and we would probably have to use !important
any way to avoid the style not taking effect.
|
||
if (element.classList.length === 0) { | ||
element.removeAttribute('class'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact i believe it is, or the next morph will consider this a change .. or let's say i think i remember this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this behavior changed with the switch to Idiomorph though
This PR adds a new
LoadingPlugin
to live components. It allows the use of adata-error
that works almost like thedata-loading
attribute, but for errors. It also fixes the loading state not clearing when an error occurs, and a typo in the hook names in the types.Little demo of the before/after of this PR :
Before :
before_pr-2024-06-10_22.31.29.mp4
After :
after_pr-2024-06-11_09.33.28.mp4