diff --git a/.gitignore b/.gitignore index 6ab010484..574512007 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,5 @@ jspm_packages /sample_react_project/ /.yarn_home/ + +.idea diff --git a/README.md b/README.md index 2ff9513c1..1989dc3fd 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,10 @@

-**NEW in v4** +**NEW in 4.2.14** -- Out of the box [frontend form validation](#user-profile-and-frontend-form-validation) šŸ„³ -- Improvements (and breaking changes in `import { useKcMessage } from "keycloakify"`. +- No more error in Keycloak logs šŸ¾ +- Templates now load in fraction of a second šŸŽ # Motivations @@ -71,13 +71,12 @@ If you already have a Keycloak custom theme, it can be easily ported to Keycloak - [GitHub Actions](#github-actions) - [Limitations](#limitations) - [`process.env.PUBLIC_URL` not supported.](#processenvpublic_url-not-supported) - - [`@font-face` importing fonts from theĀ `src/` dir](#font-face-importing-fonts-from-thesrc-dir) + - [`@font-face` importing fonts from the `src/` dir](#font-face-importing-fonts-from-the-src-dir) - [Example of setup that **won't** work](#example-of-setup-that-wont-work) - [Possible workarounds](#possible-workarounds) - [Implement context persistence (optional)](#implement-context-persistence-optional) - [Kickstart video](#kickstart-video) -- [About the errors related to `objectToJson` in Keycloak logs. (problem soon to be fixed)](#about-the-errors-related-to-objecttojson-in-keycloak-logs) -- [The pages take too long to load ? (soon to be fixed too)](#the-pages-take-too-long-to-load-) +- [FTL errors related to `ftl_object_to_js_code_declaring_an_object` in Keycloak logs.](#ftl-errors-related-to-ftl_object_to_js_code_declaring_an_object-in-keycloak-logs) - [Adding custom message (to `i18n/useKcMessage.tsx`)](#adding-custom-message-to-i18nusekcmessagetsx) - [Email domain whitelist](#email-domain-whitelist) - [Changelog highlights](#changelog-highlights) @@ -354,7 +353,7 @@ the building and publishing of the theme (the .jar file). You won't be able to [import things from your public directory **in your JavaScript code**](https://create-react-app.dev/docs/using-the-public-folder/#adding-assets-outside-of-the-module-system). (This isn't recommended anyway). -## `@font-face` importing fonts from theĀ `src/` dir +## `@font-face` importing fonts from the `src/` dir If you are building the theme with [--external-assets](#enable-loading-in-a-blink-of-a-eye-of-login-pages-) this limitation doesn't apply, you can import fonts however you see fit. @@ -438,35 +437,22 @@ flash of the blank html before the js bundle have been evaluated _NOTE: keycloak-react-theming was renamed keycloakify since this video was recorded_ [![kickstart_video](https://user-images.githubusercontent.com/6702424/108877866-f146ee80-75ff-11eb-8120-003b3c5f6dd8.png)](https://youtu.be/xTz0Rj7i2v8) -# About the errors related to `objectToJson` in Keycloak logs. +# FTL errors related to `ftl_object_to_js_code_declaring_an_object` in Keycloak logs. -The logs of your keycloak server will always show this kind of errors every time a client request a page: +If you ever encounter one of these errors: ```log FTL stack trace ("~" means nesting-related): - - Failed at: #local value = object[key] [in template "login.ftl" in macro "objectToJson_please_ignore_errors" at line 70, column 21] - - Reached through: @compress [in template "login.ftl" in macro "objectToJson_please_ignore_errors" at line 36, column 5] - - Reached through: @objectToJson_please_ignore_errors object=value depth=(dep... [in template "login.ftl" in macro "objectToJson_please_ignore_errors" at line 81, column 27] - - Reached through: @compress [in template "login.ftl" in macro "objectToJson_please_ignore_errors" at line 36, column 5] - - Reached through: @objectToJson_please_ignore_errors object=(.data_model) de... [in template "login.ftl" at line 163, column 43] + - Failed at: #local value = object[key] [in template "login.ftl" in macro "ftl_object_to_js_code_declaring_an_object" at line 70, column 21] + - Reached through: @compress [in template "login.ftl" in macro "ftl_object_to_js_code_declaring_an_object" at line 36, column 5] + - Reached through: @ftl_object_to_js_code_declaring_an_object object=value depth=(dep... [in template "login.ftl" in macro "ftl_object_to_js_code_declaring_an_object" at line 81, column 27] + - Reached through: @compress [in template "login.ftl" in macro "ftl_object_to_js_code_declaring_an_object" at line 36, column 5] + - Reached through: @ftl_object_to_js_code_declaring_an_object object=(.data_model) de... [in template "login.ftl" at line 163, column 43] ``` -Theses are expected to show up in the log. -Unfortunately, there is nothing I know of that can be done to avoid them or even mute them. -They can be, however, safely ignored. - -To [converts the `.ftl` values into a JavaScript object](https://github.com/InseeFrLab/keycloakify/blob/main/src/bin/build-keycloak-theme/generateFtl/common.ftl) -without making assumptions on the `.data_model` we have to do things that throws. -It's all-right because every statement that can fail is inside an `<#attempt><#recorver>` block but it results in errors being printed to the logs. - -# The pages take too long to load ? - -The problem of templates taking a long time to load only happens in the test environment, when you have a console logging all the above-mentioned `.ftl` warnings in real time. Logging all those warnings is what takes time. Once in production page load is way faster. - -If you run the docker container locally we acknowledge that the loading time is getting out of hand. -We are [in the process](https://github.com/InseeFrLab/keycloakify/pull/63) of resolving this issue. - -In the meantime we recommend [to run the docker container as a background task](https://youtu.be/F29Z1GaH-jk). +It's just noise, they can be safely ignored. +You can, however, and are encouraged to, report any that you would spot. +Just open an issue about it and I will release a patched version of Keycloakify in the better delays. # Adding custom message (to `i18n/useKcMessage.tsx`) diff --git a/package.json b/package.json index bc442f2a3..3b59dcfdc 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keycloakify", - "version": "4.2.13", + "version": "4.2.14-beta.1", "description": "Keycloak theme generator for Reacts app", "repository": { "type": "git", diff --git a/src/bin/build-keycloak-theme/generateFtl/Object.deepAssign.js b/src/bin/build-keycloak-theme/generateFtl/Object.deepAssign.js deleted file mode 100644 index 028d99900..000000000 --- a/src/bin/build-keycloak-theme/generateFtl/Object.deepAssign.js +++ /dev/null @@ -1,28 +0,0 @@ - -Object.defineProperty( - Object, - "deepAssign", - { - "value": function callee(target, source) { - Object.keys(source).forEach(function (key) { - var value = source[key]; - if (target[key] === undefined) { - target[key] = value; - return; - } - if (value instanceof Object) { - if (value instanceof Array) { - value.forEach(function (entry) { - target[key].push(entry); - }); - return; - } - callee(target[key], value); - return; - } - target[key] = value; - }); - return target; - } - } -); \ No newline at end of file diff --git a/src/bin/build-keycloak-theme/generateFtl/common.ftl b/src/bin/build-keycloak-theme/generateFtl/common.ftl deleted file mode 100644 index 5323e8962..000000000 --- a/src/bin/build-keycloak-theme/generateFtl/common.ftl +++ /dev/null @@ -1,208 +0,0 @@ - \ No newline at end of file diff --git a/src/bin/build-keycloak-theme/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl b/src/bin/build-keycloak-theme/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl new file mode 100644 index 000000000..b1e6627d3 --- /dev/null +++ b/src/bin/build-keycloak-theme/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl @@ -0,0 +1,290 @@ + \ No newline at end of file diff --git a/src/bin/build-keycloak-theme/generateFtl/generateFtl.ts b/src/bin/build-keycloak-theme/generateFtl/generateFtl.ts index ab4171408..a2e17203b 100644 --- a/src/bin/build-keycloak-theme/generateFtl/generateFtl.ts +++ b/src/bin/build-keycloak-theme/generateFtl/generateFtl.ts @@ -21,10 +21,6 @@ export const pageIds = [ export type PageId = typeof pageIds[number]; -function loadAdjacentFile(fileBasename: string) { - return fs.readFileSync(pathJoin(__dirname, fileBasename)).toString("utf8"); -} - export function generateFtlFilesCodeFactory(params: { cssGlobalsToDefine: Record; indexHtmlCode: string; @@ -77,8 +73,11 @@ export function generateFtlFilesCodeFactory(params: { ); //FTL is no valid html, we can't insert with cheerio, we put placeholder for injecting later. - const ftlPlaceholders = { - '{ "x": "vIdLqMeOed9sdLdIdOxdK0d" }': loadAdjacentFile("common.ftl").match(/^", - "", - "", - pageSpecificCodePlaceholder, "", - objectKeys(ftlPlaceholders)[1], + objectKeys(replaceValueBySearchValue)[1], ].join("\n"), ); @@ -129,19 +118,13 @@ export function generateFtlFilesCodeFactory(params: { const $ = cheerio.load(partiallyFixedIndexHtmlCode); - let ftlCode = $.html().replace( - pageSpecificCodePlaceholder, - [ - "", - ].join("\n"), - ); - - objectKeys(ftlPlaceholders).forEach(id => (ftlCode = ftlCode.replace(id, ftlPlaceholders[id]))); + let ftlCode = $.html(); + + Object.entries({ + ...replaceValueBySearchValue, + //If updated, don't forget to change in the ftl script as well. + "PAGE_ID_xIgLsPgGId9D8e": pageId, + }).map(([searchValue, replaceValue]) => (ftlCode = ftlCode.replace(searchValue, replaceValue))); return { ftlCode }; }