Skip to content

Commit a040e6e

Browse files
committed
improve getting root
1 parent cc9c77b commit a040e6e

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

packages/next/next-devtools-inject-tailwind.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
// This code runs on the browser.
22
// The options.target is provided from shadow-portal.tsx file.
33
function insertIntoTarget(element, options) {
4-
var root =
5-
options.target ||
6-
document.querySelector('script[data-nextjs-dev-overlay] > nextjs-portal')
7-
.shadowRoot
4+
var root = options.target
85

6+
if (!root) {
7+
var portal = [].slice
8+
.call(document.querySelectorAll('nextjs-portal'))
9+
.find((p) => p.shadowRoot.querySelector('[data-nextjs-toast]'))
10+
11+
root = portal?.shadowRoot
12+
}
13+
14+
if (!root) {
15+
// Don't spam the error overlay with internal message that the user can't control.
16+
console.log(
17+
'[Next.js DevTools] No shadow root found to apply Tailwind CSS. This is a bug in Next.js.'
18+
)
19+
return
20+
}
21+
22+
// To better indicate the style tag.
23+
element.setAttribute('data-nextjs-tailwind-style-tag', '')
924
root.insertBefore(element, root.firstChild)
1025
}
1126

0 commit comments

Comments
 (0)