@symbo.ls/brender 3.7.5 → 3.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/render.js +22 -1
- package/dist/esm/render.js +22 -1
- package/package.json +2 -2
- package/render.js +25 -1
package/dist/cjs/render.js
CHANGED
|
@@ -817,7 +817,28 @@ const renderPage = async (data, route = "/", options = {}) => {
|
|
|
817
817
|
const depth = route === "/" ? 0 : route.replace(/^\/|\/$/g, "").split("/").length;
|
|
818
818
|
const prefix = depth > 0 ? "../".repeat(depth) : "./";
|
|
819
819
|
if (hydrate2) {
|
|
820
|
-
|
|
820
|
+
let translationSeed = "";
|
|
821
|
+
if (result.ssrTranslations) {
|
|
822
|
+
const polyglotCfg2 = data.polyglot || data.config?.polyglot;
|
|
823
|
+
const storagePrefix = polyglotCfg2?.storagePrefix || "";
|
|
824
|
+
const storageLangKey = polyglotCfg2?.storageLangKey || "";
|
|
825
|
+
const seedEntries = [];
|
|
826
|
+
for (const lang2 in result.ssrTranslations) {
|
|
827
|
+
const map = result.ssrTranslations[lang2];
|
|
828
|
+
if (map && typeof map === "object") {
|
|
829
|
+
seedEntries.push(`localStorage.setItem(${JSON.stringify(storagePrefix + lang2)},${JSON.stringify(JSON.stringify(map))})`);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (storageLangKey) {
|
|
833
|
+
const defaultLang = polyglotCfg2?.defaultLang || "en";
|
|
834
|
+
seedEntries.push(`if(!localStorage.getItem(${JSON.stringify(storageLangKey)}))localStorage.setItem(${JSON.stringify(storageLangKey)},${JSON.stringify(defaultLang)})`);
|
|
835
|
+
}
|
|
836
|
+
if (seedEntries.length) {
|
|
837
|
+
translationSeed = `<script>try{${seedEntries.join(";")}}catch(e){}<\/script>
|
|
838
|
+
`;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
isrBody = `${translationSeed}<script>window.__BRENDER__ = true<\/script>
|
|
821
842
|
<script type="module" src="${prefix}${isr.clientScript}"><\/script>`;
|
|
822
843
|
} else {
|
|
823
844
|
isrBody = `<script type="module">
|
package/dist/esm/render.js
CHANGED
|
@@ -778,7 +778,28 @@ const renderPage = async (data, route = "/", options = {}) => {
|
|
|
778
778
|
const depth = route === "/" ? 0 : route.replace(/^\/|\/$/g, "").split("/").length;
|
|
779
779
|
const prefix = depth > 0 ? "../".repeat(depth) : "./";
|
|
780
780
|
if (hydrate2) {
|
|
781
|
-
|
|
781
|
+
let translationSeed = "";
|
|
782
|
+
if (result.ssrTranslations) {
|
|
783
|
+
const polyglotCfg2 = data.polyglot || data.config?.polyglot;
|
|
784
|
+
const storagePrefix = polyglotCfg2?.storagePrefix || "";
|
|
785
|
+
const storageLangKey = polyglotCfg2?.storageLangKey || "";
|
|
786
|
+
const seedEntries = [];
|
|
787
|
+
for (const lang2 in result.ssrTranslations) {
|
|
788
|
+
const map = result.ssrTranslations[lang2];
|
|
789
|
+
if (map && typeof map === "object") {
|
|
790
|
+
seedEntries.push(`localStorage.setItem(${JSON.stringify(storagePrefix + lang2)},${JSON.stringify(JSON.stringify(map))})`);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
if (storageLangKey) {
|
|
794
|
+
const defaultLang = polyglotCfg2?.defaultLang || "en";
|
|
795
|
+
seedEntries.push(`if(!localStorage.getItem(${JSON.stringify(storageLangKey)}))localStorage.setItem(${JSON.stringify(storageLangKey)},${JSON.stringify(defaultLang)})`);
|
|
796
|
+
}
|
|
797
|
+
if (seedEntries.length) {
|
|
798
|
+
translationSeed = `<script>try{${seedEntries.join(";")}}catch(e){}<\/script>
|
|
799
|
+
`;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
isrBody = `${translationSeed}<script>window.__BRENDER__ = true<\/script>
|
|
782
803
|
<script type="module" src="${prefix}${isr.clientScript}"><\/script>`;
|
|
783
804
|
} else {
|
|
784
805
|
isrBody = `<script type="module">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/brender",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.6",
|
|
4
4
|
"license": "CC-BY-NC-4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"dev:rita": "node examples/serve-rita.js"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@symbo.ls/helmet": "^3.7.
|
|
39
|
+
"@symbo.ls/helmet": "^3.7.6",
|
|
40
40
|
"linkedom": "^0.16.8"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
package/render.js
CHANGED
|
@@ -1024,7 +1024,31 @@ export const renderPage = async (data, route = '/', options = {}) => {
|
|
|
1024
1024
|
// True hydration: signal the SPA to adopt existing DOM nodes
|
|
1025
1025
|
// instead of creating new ones. The SPA detects __BRENDER__ flag
|
|
1026
1026
|
// and uses onlyResolveExtends + node adoption.
|
|
1027
|
-
|
|
1027
|
+
//
|
|
1028
|
+
// Seed client-side polyglot with SSR translations so that
|
|
1029
|
+
// el.call('polyglot', key) resolves immediately during hydration
|
|
1030
|
+
// instead of showing raw keys until the async fetch completes.
|
|
1031
|
+
let translationSeed = ''
|
|
1032
|
+
if (result.ssrTranslations) {
|
|
1033
|
+
const polyglotCfg = data.polyglot || data.config?.polyglot
|
|
1034
|
+
const storagePrefix = polyglotCfg?.storagePrefix || ''
|
|
1035
|
+
const storageLangKey = polyglotCfg?.storageLangKey || ''
|
|
1036
|
+
const seedEntries = []
|
|
1037
|
+
for (const lang in result.ssrTranslations) {
|
|
1038
|
+
const map = result.ssrTranslations[lang]
|
|
1039
|
+
if (map && typeof map === 'object') {
|
|
1040
|
+
seedEntries.push(`localStorage.setItem(${JSON.stringify(storagePrefix + lang)},${JSON.stringify(JSON.stringify(map))})`)
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
if (storageLangKey) {
|
|
1044
|
+
const defaultLang = polyglotCfg?.defaultLang || 'en'
|
|
1045
|
+
seedEntries.push(`if(!localStorage.getItem(${JSON.stringify(storageLangKey)}))localStorage.setItem(${JSON.stringify(storageLangKey)},${JSON.stringify(defaultLang)})`)
|
|
1046
|
+
}
|
|
1047
|
+
if (seedEntries.length) {
|
|
1048
|
+
translationSeed = `<script>try{${seedEntries.join(';')}}catch(e){}</script>\n`
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
isrBody = `${translationSeed}<script>window.__BRENDER__ = true</script>
|
|
1028
1052
|
<script type="module" src="${prefix}${isr.clientScript}"></script>`
|
|
1029
1053
|
} else {
|
|
1030
1054
|
// Legacy swap mode: SPA creates new DOM, MutationObserver removes brender nodes
|