-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
BUG: No id for elements not having styles but with script
, which results in script not running for those elements
#5441
Comments
The issue is caused by the use of |
This was referenced May 24, 2024
This was referenced Aug 27, 2024
This was referenced Sep 20, 2024
This was referenced Oct 26, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GrapesJS version
What browser are you using?
Chrome latest
Reproducible demo link
https://github.com/padcom/grapesjs-no-id-for-element-example
Describe the bug
When creating custom GrapesJS components, if those components have the
script()
(runtime behavior for component) and no styles are being applied to that component then the root element doesn't have theid
attribute which then fails thedocument.querySelectorAll('#<id-goes-here')
and the runtime script is not called.In the given example, I have created a special custom element, called
<content-preview>
(https://github.com/padcom/grapesjs-no-id-for-element-example/blob/master/preview.ts) so that I can present the issue on one page. Here are the reproduction steps:npm install
npm start
example
block on to the canvasCurrent result:
You will see in the console just one log stating that the component has been initialized inside the
<iframe>
Expected result:
You will also see in the console a log stating that the component has been initialized inside the page
This will automatically generate the
id
for that element, because styles need to have a reference to something which in turn allows the initialization script to also find the component and the initialization message that was previously missing appears in the console.As a workaround, one can render the containing element with the
id
attribute manually. This, however, will only render those attributes that have been specifically mentioned in thetoHTML()
method, so it is a weak solution. It'd be much better if when filtering out attributes such asid
GrapesJS would take thescript
element into account and preserve theid
in the final HTML output generated bygetHtml()
. This is shown in https://github.com/padcom/grapesjs-no-id-for-element-example/blob/master/main.ts#L22Code of Conduct
The text was updated successfully, but these errors were encountered: