-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Show messages for users if the ROOT_URL is wrong, show JavaScript errors #18971
Conversation
@go-gitea/maintainers I think we need this PR to save all active maintainers' time. |
How about to force redirect to |
It will cause problems if the ROOT_URL is |
And I think we can wait for a few days before merge after lgtm/done. Maybe some maintainers have new opinions. 🙏 |
…hance to hide error messages by customized CSS styles.
… part, then it's much safer.
@@ -0,0 +1,44 @@ | |||
<script> | |||
<!-- /* eslint-disable */ --> | |||
window.addEventListener('error', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);}); |
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.
Should probably create a separate webpack chunk that loads beforeindex.js
for this instead of inlining it. That way, you also shouldn't need this global variable.
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.
However, index.js
is very late, the layout is:
window.addEventListener('error')
window.config = // error occurs
template <script> // error occurs
index.js
- bootstrap.js (the old publicpath.js)
- others (initXxx) // error occurs
So the window.addEventListener
must be the first one in script tag.
That will be putting up a bandaid around possible incorrect configuration. To show the error seems the best option IMO. If they suddenly will be redirected to a new URL, how will they know what's going on and how to fix it? |
This comment was marked as off-topic.
This comment was marked as off-topic.
Let's merge and see user's reactions. If it helps, that's good. If some users feel annoying, we should find the real problem behind these users. |
* giteaoffical/main: (31 commits) Add Package Registry (go-gitea#16510) Show messages for users if the ROOT_URL is wrong, show JavaScript errors (go-gitea#18971) [skip ci] Updated translations via Crowdin Make git.OpenRepository accept Context (go-gitea#19260) Use full output of git show-ref --tags to get tags for PushUpdateAddTag (go-gitea#19235) When conflicts have been previously detected ensure that they can be resolved (go-gitea#19247) More commit info from API (go-gitea#19252) Move some issue methods as functions (go-gitea#19255) Move project files into models/project sub package (go-gitea#17704) Granular webhook events in editHook (go-gitea#19251) Provide configuration to allow camo-media proxying (go-gitea#12802) Move init repository related functions to modules (go-gitea#19159) Move organization related structs into sub package (go-gitea#18518) Refactor repo clone button and repo clone links, fix JS error on empty repo page (go-gitea#19208) Show last cron messages on monitor page (go-gitea#19223) Allow API to create file on empty repo (go-gitea#19224) Use goproxy.io instead of goproxy.cn (go-gitea#19242) New cron task: delete old system notices (go-gitea#19219) Let web and API routes have different auth methods group (go-gitea#19168) Only send webhook events to active system webhooks and only deliver to active hooks (go-gitea#19234) ...
FYI: Using If all URLs in template can be refactored to use Relative URL correctly, then we do not need to force users set ROOT_URL correctly again and again. |
Some updates about this PR (which may be useful for future readers). The
And
The ROOT_URL detection also helps issues like #19972 and some users in discord. I believe it's on the right way. If there are new issues about it in the future, these related bugs could also be fixed. |
ROOT_URL issues
Many maintainers have answered the issues about incorrect ROOT_URL again and again.
Using
HTMLURL
(absolute URL) in templates is the root case that Gitea can only serve web under ROOT_URL. That's why we have to force users to set ROOT_URL correctly, and that's why this PR came. If all URLs in template can be refactored to use Relative URL correctly, then we do not need to force users set ROOT_URL correctly again and again.Actually, at the moment, there are 2 major cases:
AppSubUrl != ""
and users try to accesshttp://host:3000/
)ROOT_URL
is wrong, then many URLs in Gitea are broken.This PR can detect these problems, and show enough information to users. No i18n is needed because these messages should only be processed by Gitea admin.
JavaScript error issues
And, there are many users affected by JavaScript errors:
And more and more
If these problems (JS errors) can be found at first time, then maintainers do not need to ask about how bug occurs again and again.
Screenshots:
Can not load
index.js
Incorrect ROOT_URL
JavaScript error
mainly caused by incorrect customized templates, or incorrect cached files
window.config
brokenFAQ
What if some users do not want to see these errors?
There is a specialized CSS class "js-global-error" for the error message, then end users still have a chance to hide these error messages by customized CSS styles. But please DO NOT do so, otherwise if the users ignore the warning, there will be a lot of UI problem on their side, for example: the issue preview / inline PR comment don't work, etc.
What if I see "Your ROOT_URL in app.ini is undefined"
There must be something wrong with your JS assets or templates. Check your CDN/static files/customized templates, etc. Make sure the JS assets and templates are correct.
What if I see "Your ROOT_URL in app.ini is https://..... but you are visiting https://....."
Check the ROOT_URL config in your
app.ini
And check Gitea's startup logs:
Make sure the ROOT_URL matches the base URL you are visiting.
What if I see "JavaScript error"
It could be caused by: