-
-
Notifications
You must be signed in to change notification settings - Fork 79.2k
Backdrop: Fix stale body by removing unnecessary default #34092
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
Conversation
|
try to put any comments for future reference 😃 |
Oh! Do you mean comments in the code to explain the "bug"? I appreciate you helping me navigate the ecosystem over here - it's still new to me 😄 |
|
Yes. simple Comments that will guide us on future needs and changes. You also can try use the: rootElement: 'body',and inside |
24f8a09 to
e94beac
Compare
👍
That had also been my impression, but it looks like it's not the case: https://github.com/hotwired/turbo/blob/aae03ada8be4b46899330364d712cc1ae57f2400/src/core/drive/page_renderer.ts#L91-L92
I've made that change :). The "pro" is that the |
e94beac to
64fcbd7
Compare
|
Before force pushing you commits, try to leave them alive for a bit. The previous commit was more valid. Try to check why was failing |
Sorry about that - I have that same pet peeve when I'm the maintainer :). I can always rebase/squash a bit later. So there are 2 possible approaches:
config.rootElement = getElement(config.rootElement)The problem is that the user SHOULD be allowed to explicitly pass -config.rootElement = getElement(config.rootElement)
+config.rootElement = config.rootElement ? getElement(config.rootElement) : document.body
const Default = {
// ...
- rootElement: document.body,
+ rootElement: null,
}If you'd like any changes - or if you think option (2) might be nicer, please let me know. Thanks for the comments already :) Cheers! |
64fcbd7 to
767ad7c
Compare
|
did you take into consideration that may the tests where wrong scoped to a false expectation? ;) To help you on this, I am referring to this The initial problem was that if someone had the bootstrap script in the To come up to an end, I believe that the test is wrong (with the existing codebase) /cc @alpadev any help on this? |
|
Not sure why someone would pass in Given that we validate the config parameters and they are defined like const DefaultType = {
isVisible: 'boolean',
isAnimated: 'boolean',
rootElement: 'element',
clickCallback: '(function|null)'
}it shouldn't be possible to use |
|
I mean, I was thinking of a different approach back then (#33889). But since I missed there was already some PR in progress and someone started to argue that my solution might be overkill, I closed this in favor of the merged one. I guess my solution would have worked for your use-case too, so not sure what to propose here. Also wouldn't it be possible to explicitly pass in |
|
Hi! Ok then, I've pushed another approach. This: A) Does not allow B) This is still "lazy" thanks to
That's interesting. If I understand you correctly, you're saying that an alternative fix would be to "leave Backdrop alone", but explicitly pass Cheers! |
|
Your last approach seems valid to me. 👍 It follows the idea of delaying things until the component is used and by using a string we make sure that some replaced element wouldn't be stuck in the memory because we hold a reference to it. On a sidenote, initially we pushed that implementation in kind of a rush because it prevented people from using the script files in the head section and blocked their development. It wasn't the best solution at that time but solved the problem people had. @GeoSot WDYT? It's your baby 😊 |
The current config can cause the "body" to become stale. Specifically, if the entire body element is swapped out for a new body element, then the backdrop will continue to append itself to the original body element, since it's stored in memory as a reference on this object. This also no longer allows an explicit null to be passed to Backdrop's rootElement This still accomplishes the laziness of "not finding the rootElement until the Backdrop is created" to avoid problems of the JavaScript being included inside <head> (so, before body is available).
beb2691 to
3094983
Compare
🤣 ❤️ Seems fine to my eyes, too |
The current config can cause the "body" to become stale. Specifically, if the entire body element is swapped out for a new body element, then the backdrop will continue to append itself to the original body element, since it's stored in memory as a reference on this object. This also no longer allows an explicit null to be passed to Backdrop's rootElement This still accomplishes the laziness of "not finding the rootElement until the Backdrop is created" to avoid problems of the JavaScript being included inside <head> (so, before body is available).
Hi there!
I'm using Turbo, where the entire
bodyelement is swapped out at times. This causes a bug with Backdrop, as it stores the originalbodyelement in theDefaultobject. This is the flow:bodyfor a newbodyElement)On (3), the
Backdropwill append itself to the originalbodyElement from (1), not the new body element.Also, the default is unnecessary: in
_getConfig(), ifconfig.rootElementis falsy, then it already defaults todocument.body(which is why I didn't add any tests: there are tests already to make sure therootElementcan be configured):bootstrap/js/src/util/backdrop.js
Line 93 in 1366659
Please let me know if any tweaks are needed.
Thanks!