Show messages for users if the ROOT_URL is wrong, show JavaScript errors (#18971)
* ROOT_URL issues: some users did wrong to there app.ini config, then:
* The assets can not be loaded (AppSubUrl != "" and users try to access http://host:3000/)
*The ROOT_URL is wrong, then many URLs in Gitea are broken.
Now Gitea show enough information to users.
* JavaScript error issues, there are many users affected by JavaScript errors, some are caused by frontend bugs, some are caused by broken customized templates. If these JS errors can be found at first time, then maintainers do not need to ask about how bug occurs again and again.
* Some people like to modify the `head.tmpl`, so we separate the script part to `head_script.tmpl`, then it's much safer.
* use specialized CSS class "js-global-error", end users still have a chance to hide error messages by customized CSS styles.
2022-03-30 07:52:24 +02:00
{{ /*
==== DO NOT EDIT ====
If you are customizing Gitea, please do not change this file.
If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly.
*/}}
< script >
2023-08-22 04:30:02 +02:00
{{/* before our JS code gets loaded, use arrays to store errors, then the arrays will be switched to our error handler later */}}
Show messages for users if the ROOT_URL is wrong, show JavaScript errors (#18971)
* ROOT_URL issues: some users did wrong to there app.ini config, then:
* The assets can not be loaded (AppSubUrl != "" and users try to access http://host:3000/)
*The ROOT_URL is wrong, then many URLs in Gitea are broken.
Now Gitea show enough information to users.
* JavaScript error issues, there are many users affected by JavaScript errors, some are caused by frontend bugs, some are caused by broken customized templates. If these JS errors can be found at first time, then maintainers do not need to ask about how bug occurs again and again.
* Some people like to modify the `head.tmpl`, so we separate the script part to `head_script.tmpl`, then it's much safer.
* use specialized CSS class "js-global-error", end users still have a chance to hide error messages by customized CSS styles.
2022-03-30 07:52:24 +02:00
window.addEventListener('error', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);});
2023-08-22 04:30:02 +02:00
window.addEventListener('unhandledrejection', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);});
Show messages for users if the ROOT_URL is wrong, show JavaScript errors (#18971)
* ROOT_URL issues: some users did wrong to there app.ini config, then:
* The assets can not be loaded (AppSubUrl != "" and users try to access http://host:3000/)
*The ROOT_URL is wrong, then many URLs in Gitea are broken.
Now Gitea show enough information to users.
* JavaScript error issues, there are many users affected by JavaScript errors, some are caused by frontend bugs, some are caused by broken customized templates. If these JS errors can be found at first time, then maintainers do not need to ask about how bug occurs again and again.
* Some people like to modify the `head.tmpl`, so we separate the script part to `head_script.tmpl`, then it's much safer.
* use specialized CSS class "js-global-error", end users still have a chance to hide error messages by customized CSS styles.
2022-03-30 07:52:24 +02:00
window.config = {
appUrl: '{{ AppUrl }} ',
appSubUrl: '{{ AppSubUrl }} ',
2022-08-23 14:58:04 +02:00
assetVersionEncoded: encodeURIComponent('{{ AssetVersion }} '), // will be used in URL construction directly
Show messages for users if the ROOT_URL is wrong, show JavaScript errors (#18971)
* ROOT_URL issues: some users did wrong to there app.ini config, then:
* The assets can not be loaded (AppSubUrl != "" and users try to access http://host:3000/)
*The ROOT_URL is wrong, then many URLs in Gitea are broken.
Now Gitea show enough information to users.
* JavaScript error issues, there are many users affected by JavaScript errors, some are caused by frontend bugs, some are caused by broken customized templates. If these JS errors can be found at first time, then maintainers do not need to ask about how bug occurs again and again.
* Some people like to modify the `head.tmpl`, so we separate the script part to `head_script.tmpl`, then it's much safer.
* use specialized CSS class "js-global-error", end users still have a chance to hide error messages by customized CSS styles.
2022-03-30 07:52:24 +02:00
assetUrlPrefix: '{{ AssetUrlPrefix }} ',
runModeIsProd: {{ .RunModeIsProd }} ,
customEmojis: {{ CustomEmojis }} ,
csrfToken: '{{ .CsrfToken }} ',
pageData: {{ .PageData }} ,
notificationSettings: {{ NotificationSettings }} , {{/*a map provided by NewFuncMap in helper.go*/}}
enableTimeTracking: {{ EnableTimetracking }} ,
2023-04-03 12:06:57 +02:00
{{ if or .Participants .Assignees .MentionableTeams }}
2023-06-20 05:32:49 +02:00
mentionValues: Array.from(new Map([
2023-04-03 12:06:57 +02:00
{{- range .Participants -}}
['{{ .Name }} ', {key: '{{ .Name }} {{ .FullName }} ', value: '{{ .Name }} ', name: '{{ .Name }} ', fullname: '{{ .FullName }} ', avatar: '{{ .AvatarLink $.Context }} '}],
{{- end -}}
{{- range .Assignees -}}
['{{ .Name }} ', {key: '{{ .Name }} {{ .FullName }} ', value: '{{ .Name }} ', name: '{{ .Name }} ', fullname: '{{ .FullName }} ', avatar: '{{ .AvatarLink $.Context }} '}],
{{- end -}}
{{- range .MentionableTeams -}}
['{{ $.MentionableTeamsOrg }} /{{ .Name }} ', {key: '{{ $.MentionableTeamsOrg }} /{{ .Name }} ', value: '{{ $.MentionableTeamsOrg }} /{{ .Name }} ', name: '{{ $.MentionableTeamsOrg }} /{{ .Name }} ', avatar: '{{ $.MentionableTeamsOrgAvatar }} '}],
{{- end -}}
Show messages for users if the ROOT_URL is wrong, show JavaScript errors (#18971)
* ROOT_URL issues: some users did wrong to there app.ini config, then:
* The assets can not be loaded (AppSubUrl != "" and users try to access http://host:3000/)
*The ROOT_URL is wrong, then many URLs in Gitea are broken.
Now Gitea show enough information to users.
* JavaScript error issues, there are many users affected by JavaScript errors, some are caused by frontend bugs, some are caused by broken customized templates. If these JS errors can be found at first time, then maintainers do not need to ask about how bug occurs again and again.
* Some people like to modify the `head.tmpl`, so we separate the script part to `head_script.tmpl`, then it's much safer.
* use specialized CSS class "js-global-error", end users still have a chance to hide error messages by customized CSS styles.
2022-03-30 07:52:24 +02:00
]).values()),
{{ end }}
mermaidMaxSourceCharacters: {{ MermaidMaxSourceCharacters }} ,
{{/* this global i18n object should only contain general texts. for specialized texts, it should be provided inside the related modules by: (1) API response (2) HTML data-attribute (3) PageData */}}
i18n: {
2023-09-25 10:56:50 +02:00
copy_success: {{ ctx .Locale.Tr "copy_success" }} ,
copy_error: {{ ctx .Locale.Tr "copy_error" }} ,
error_occurred: {{ ctx .Locale.Tr "error.occurred" }} ,
network_error: {{ ctx .Locale.Tr "error.network_error" }} ,
remove_label_str: {{ ctx .Locale.Tr "remove_label_str" }} ,
modal_confirm: {{ ctx .Locale.Tr "modal.confirm" }} ,
modal_cancel: {{ ctx .Locale.Tr "modal.cancel" }} ,
2024-03-15 03:05:31 +01:00
more_items: {{ ctx .Locale.Tr "more_items" }} ,
Show messages for users if the ROOT_URL is wrong, show JavaScript errors (#18971)
* ROOT_URL issues: some users did wrong to there app.ini config, then:
* The assets can not be loaded (AppSubUrl != "" and users try to access http://host:3000/)
*The ROOT_URL is wrong, then many URLs in Gitea are broken.
Now Gitea show enough information to users.
* JavaScript error issues, there are many users affected by JavaScript errors, some are caused by frontend bugs, some are caused by broken customized templates. If these JS errors can be found at first time, then maintainers do not need to ask about how bug occurs again and again.
* Some people like to modify the `head.tmpl`, so we separate the script part to `head_script.tmpl`, then it's much safer.
* use specialized CSS class "js-global-error", end users still have a chance to hide error messages by customized CSS styles.
2022-03-30 07:52:24 +02:00
},
};
{{/* in case some pages don't render the pageData, we make sure it is an object to prevent null access */}}
window.config.pageData = window.config.pageData || {};
< / script >
Introduce customized HTML elements, fix incorrect AppUrl usages in templates (#22861)
This PR follows:
* #21986
* #22831
This PR also introduce customized HTML elements, which would also help
problems like:
* #17760
* #21429
* #21440
With customized HTML elements, there won't be any load-search-replace
operations, and it can avoid page flicking (which @silverwind cares a
lot).
Browser support:
https://developer.mozilla.org/en-US/docs/Web/API/Window/customElements
# FAQ
## Why the component has the prefix?
As usual, I would strongly suggest to add prefixes for our own/private
names. The dedicated prefix will avoid conflicts in the future, and it
makes it easier to introduce various 3rd components, like GitHub's
`relative-time` component. If there is no prefix, it's impossible to
introduce another public component with the same name in the future.
## Why the `custcomp.js` is loaded before HTML body? The `index.js` is
after HTML body.
Customized components must be registered before the content loading.
Otherwise there would be still some flicking.
`custcomp.js` should have its own dependencies and should be very light,
so it won't affect the page loading time too much.
## Why use `data-url` attribute but not use the `textContent`?
According to the standard, the `connectedCallback` occurs on the
tag-opening moment. The element's children are not ready yet.
## Why not use `{{.GuessCurrentOrigin $.ctx ...}}` to let backend decide
the absolute URL?
It's difficult for backend to guess the correct protocol(scheme)
correctly with zero configuration. Generating the absolute URL from
frontend can guarantee that the URL is 100% correct -- since the user is
visiting it.
# Screenshot
<details>
![image](https://user-images.githubusercontent.com/2114189/218256757-a267c8ba-3108-4755-9ae5-329f1b08f615.png)
</details>
2023-02-17 15:02:20 +01:00
< script src = " {{ AssetUrlPrefix }} /js/webcomponents.js?v= {{ AssetVersion }} " ></ script >