-
-
Notifications
You must be signed in to change notification settings - Fork 7
Fix: func sseError not found (Extension Conflict) #496
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,29 @@ export default function RootLayout({ | |
| }>) { | ||
| return ( | ||
| <html lang="en" suppressHydrationWarning> | ||
| <head> | ||
| <script | ||
| dangerouslySetInnerHTML={{ | ||
| __html: ` | ||
| (function() { | ||
| const htmxEvents = [ | ||
| 'sseError', 'sseOpen', 'swapError', 'targetError', 'timeout', | ||
| 'validation:validate', 'validation:failed', 'validation:halted', | ||
| 'xhr:abort', 'xhr:loadend', 'xhr:loadstart' | ||
| ]; | ||
| htmxEvents.forEach(event => { | ||
| const funcName = 'func ' + event; | ||
| if (typeof window[funcName] === 'undefined') { | ||
| window[funcName] = function() { | ||
| console.warn('HTMX event handler "' + funcName + '" was called but not defined. Providing safety fallback.'); | ||
| }; | ||
| } | ||
| }); | ||
| })(); | ||
| `, | ||
| }} | ||
| /> | ||
| </head> | ||
|
Comment on lines
+68
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This script uses Also, because this is a root layout in Next.js, you should be deliberate about when the script runs. If the goal is to prevent early calls from extensions, consider SuggestionConsider switching to
Example: import Script from 'next/script'
// ...
<head>
<Script id="htmx-func-fallback" strategy="beforeInteractive">
{`(function(){
if (typeof window === 'undefined') return;
const htmxEvents = [/* ... */];
for (const event of htmxEvents) {
const funcName = 'func ' + event;
if (typeof window[funcName] === 'undefined') {
window[funcName] = function() {};
}
}
})();`}
</Script>
</head>Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this change.
Comment on lines
+68
to
+90
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Inline script may be blocked by CSP; prefer external script or nonce. If 🛠️ Proposed refactor (external script)+import Script from 'next/script'
...
- <head>
- <script
- dangerouslySetInnerHTML={{
- __html: `
- (function() {
- const htmxEvents = [
- 'sseError', 'sseOpen', 'swapError', 'targetError', 'timeout',
- 'validation:validate', 'validation:failed', 'validation:halted',
- 'xhr:abort', 'xhr:loadend', 'xhr:loadstart'
- ];
- htmxEvents.forEach(event => {
- const funcName = 'func ' + event;
- if (typeof window[funcName] === 'undefined') {
- window[funcName] = function() {
- console.warn('HTMX event handler "' + funcName + '" was called but not defined. Providing safety fallback.');
- };
- }
- });
- })();
- `,
- }}
- />
- </head>
+ <head>
+ <Script src="/htmx-fallback.js" strategy="beforeInteractive" />
+ </head>Then add (function () {
const htmxEvents = [
'sseError', 'sseOpen', 'swapError', 'targetError', 'timeout',
'validation:validate', 'validation:failed', 'validation:halted',
'xhr:abort', 'xhr:loadend', 'xhr:loadstart'
];
htmxEvents.forEach(event => {
const funcName = 'func ' + event;
if (typeof window[funcName] === 'undefined') {
window[funcName] = function () {
console.warn(
'HTMX event handler "' + funcName + '" was called but not defined. Providing safety fallback.'
);
};
}
});
})();🧰 Tools🪛 ast-grep (0.40.5)[warning] 69-69: Usage of dangerouslySetInnerHTML detected. This bypasses React's built-in XSS protection. Always sanitize HTML content using libraries like DOMPurify before injecting it into the DOM to prevent XSS attacks. (react-unsafe-html-injection) 🪛 Biome (2.3.13)[error] 70-70: Avoid passing content using the dangerouslySetInnerHTML prop. Setting content using code can expose users to cross-site scripting (XSS) attacks (lint/security/noDangerouslySetInnerHtml) 🤖 Prompt for AI Agents |
||
| <body | ||
| className={cn( | ||
| 'font-sans antialiased', | ||
|
|
||
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.
The fallback function logs a warning every time an extension triggers the missing handler, which can spam the console (and, in some setups, log aggregation) during SSE streams. Since the intent is resilience, not observability, this should ideally warn once per handler (or be gated behind a development check).
Suggestion
Rate-limit or dedupe the warning per handler (or only warn in development). For example:
Alternatively, log only when
process.env.NODE_ENV !== 'production'.Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion.