这是indexloc提供的服务,不要输入任何密码
Skip to content

Rails: Link navigation causes <style> inside <noscript> to be evaluated #1464

@dari-us

Description

@dari-us

I ran into a strange issue, where a link click causes the <noscript> tag and its child <style> on my page to be parsed and evaluated.
Adding an id and data-turbo-permanent="true" is a workaround for this, but only works for successful visits.
On the error page, the content of <noscript> remains invisible, but it contains a <style> tag, which is evaluated and causes the content of the page to be set to display: none;.
The errors on my website are not static; they are rendered within the default layout and attempt to keep navigation/breadcrumbs as intact as possible.
However, when Turbo renders 4xx/5xx errors, it seems to re-evaluate everything, even elements that are marked as permanent.
My browser also warns me that there may be no more than one importmap, which supports my "re-evaluate everything" assumption.

My workaround is this ugly hack:

document.addEventListener("turbo:before-render", (event) => {
	const noscriptTag = event.detail.newBody.querySelector("noscript");
	if (noscriptTag && noscriptTag.querySelector("style")) noscriptTag.innerText = noscriptTag.innerHTML;
});

Also, the warning about a second importmap being loaded remains, which is also not nice.

Surely this can't be the intended behavior? What is causing the duplicate importmap?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions