@alignable/bifrost 1.0.20 → 1.0.22
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/renderer/Wrapper.js
CHANGED
|
@@ -4,7 +4,13 @@ import { usePageContext } from "vike-react/usePageContext";
|
|
|
4
4
|
function Wrapper({ children }) {
|
|
5
5
|
const pageContext = usePageContext();
|
|
6
6
|
if (pageContext.isClientSide && pageContext._shouldEmitBeforeRender) {
|
|
7
|
-
|
|
7
|
+
try {
|
|
8
|
+
window.Turbolinks.controller.viewWillRender();
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.error("Error calling window.Turbolinks.controller.viewWillRender:", error);
|
|
11
|
+
console.error("Turbolinks:", window.Turbolinks);
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
8
14
|
pageContext._shouldEmitBeforeRender = false;
|
|
9
15
|
}
|
|
10
16
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../renderer/Wrapper.tsx"],"sourcesContent":["import React from \"react\";\nimport { usePageContext } from \"vike-react/usePageContext\";\n\nexport default function Wrapper({ children }: { children: React.ReactNode }) {\n const pageContext = usePageContext();\n\n // We want to fire `turbolinks:before-render` as late as possible - synchronously before rendering the page.\n // This is important because before-render scripts may clear the DOM, and we want to paint the new page immediately\n // onBeforeRenderClient awaits for promises so there is a delay\n if (pageContext.isClientSide && pageContext._shouldEmitBeforeRender) {\n window.Turbolinks.controller.viewWillRender();\n pageContext._shouldEmitBeforeRender = false;\n }\n \n return <>{children}</>;\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAClB,SAAS,sBAAsB;AAEhB,SAAR,QAAyB,EAAE,SAAS,GAAkC;AAC3E,QAAM,cAAc,eAAe;AAKnC,MAAI,YAAY,gBAAgB,YAAY,yBAAyB;AACnE,
|
|
1
|
+
{"version":3,"sources":["../../renderer/Wrapper.tsx"],"sourcesContent":["import React from \"react\";\nimport { usePageContext } from \"vike-react/usePageContext\";\n\nexport default function Wrapper({ children }: { children: React.ReactNode }) {\n const pageContext = usePageContext();\n\n // We want to fire `turbolinks:before-render` as late as possible - synchronously before rendering the page.\n // This is important because before-render scripts may clear the DOM, and we want to paint the new page immediately\n // onBeforeRenderClient awaits for promises so there is a delay\n if (pageContext.isClientSide && pageContext._shouldEmitBeforeRender) {\n try {\n window.Turbolinks.controller.viewWillRender();\n } catch (error) {\n // Some logging to diagnose `window.Turbolinks.controller.viewWillRender is not a function`. Remove this after fixing\n console.error(\"Error calling window.Turbolinks.controller.viewWillRender:\", error);\n console.error(\"Turbolinks:\", window.Turbolinks);\n\n throw error;\n }\n \n pageContext._shouldEmitBeforeRender = false;\n }\n \n return <>{children}</>;\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAClB,SAAS,sBAAsB;AAEhB,SAAR,QAAyB,EAAE,SAAS,GAAkC;AAC3E,QAAM,cAAc,eAAe;AAKnC,MAAI,YAAY,gBAAgB,YAAY,yBAAyB;AACnE,QAAI;AACF,aAAO,WAAW,WAAW,eAAe;AAAA,IAC9C,SAAS,OAAP;AAEA,cAAQ,MAAM,8DAA8D,KAAK;AACjF,cAAQ,MAAM,eAAe,OAAO,UAAU;AAE9C,YAAM;AAAA,IACR;AAEA,gBAAY,0BAA0B;AAAA,EACxC;AAEA,SAAO,0DAAG,QAAS;AACrB;","names":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const _default: "<script>window.Turbolinks = {controller:{restorationIdentifier: '',started:false},visit:(...a)=>{addEventListener(\"turbolinks:start\", () => {window.Turbolinks.visit(...a)})}};addEventListener(\"DOMContentLoaded\", () => {\n const event = new Event(\"turbolinks:load\", { bubbles: true, cancelable: true });\n event.data = {url: window.location.href};\n document.dispatchEvent(event); \n});window._disableAutomaticLinkInterception = true;addEventListener(\"popstate\", (e) => {\n if(e.state && e.state.turbolinks) window.location.reload();\n});</script>";
|
|
1
|
+
declare const _default: "<script>window.Turbolinks = {controller:{restorationIdentifier: '',started:false,viewWillRender:(...a)=>{addEventListener(\"turbolinks:start\", () => {window.Turbolinks.controller.viewWillRender(...a)})}},visit:(...a)=>{addEventListener(\"turbolinks:start\", () => {window.Turbolinks.visit(...a)})}};addEventListener(\"DOMContentLoaded\", () => {\n const event = new Event(\"turbolinks:load\", { bubbles: true, cancelable: true });\n event.data = {url: window.location.href};\n document.dispatchEvent(event); \n});window._disableAutomaticLinkInterception = true;addEventListener(\"popstate\", (e) => {\n if(e.state && e.state.turbolinks) window.location.reload();\n});</script>";
|
|
2
2
|
|
|
3
3
|
export { _default as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// renderer/headHtmlBegin.ts
|
|
2
|
-
var turbolinksIOSCompat = `window.Turbolinks = {controller:{restorationIdentifier: '',started:false},visit:(...a)=>{addEventListener("turbolinks:start", () => {window.Turbolinks.visit(...a)})}};`;
|
|
2
|
+
var turbolinksIOSCompat = `window.Turbolinks = {controller:{restorationIdentifier: '',started:false,viewWillRender:(...a)=>{addEventListener("turbolinks:start", () => {window.Turbolinks.controller.viewWillRender(...a)})}},visit:(...a)=>{addEventListener("turbolinks:start", () => {window.Turbolinks.visit(...a)})}};`;
|
|
3
3
|
var turbolinksLoadEvent = `addEventListener("DOMContentLoaded", () => {
|
|
4
4
|
const event = new Event("turbolinks:load", { bubbles: true, cancelable: true });
|
|
5
5
|
event.data = {url: window.location.href};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../renderer/headHtmlBegin.ts"],"sourcesContent":["// We use headHtmlStart instead of +Head.tsx to avoid issues with userland usage of `+Head.clear.tsx` overwriting our handling\n\n// Register turbolinks global for ios to hook into\n// Also allows Turbolinks.visit to be called before Turbolinks is started (Vike loads async)\nconst turbolinksIOSCompat = `window.Turbolinks = {controller:{restorationIdentifier: '',started:false},visit:(...a)=>{addEventListener(\"turbolinks:start\", () => {window.Turbolinks.visit(...a)})}};`;\n\n/// emit turbolinks:load on DOMContentLoaded\nconst turbolinksLoadEvent = `addEventListener(\"DOMContentLoaded\", () => {\n const event = new Event(\"turbolinks:load\", { bubbles: true, cancelable: true });\n event.data = {url: window.location.href};\n document.dispatchEvent(event); \n});`;\n\n// Tells vike not to do link interception\nconst disableVikeLinkInterception = `window._disableAutomaticLinkInterception = true;`;\n\n/**\n * Hard reload when user navigates to a passthru turbolinks page.\n * Turbolinks navigates with history.pushState. When navigating passthru => bifrost (tracked scripts change), it reloads page.\n * Now on bifrost page, if user clicks back button, the browser sees the original navigation as initiated by pushState,\n * so the browser does not load the page. We detect this and force a reload.\n *\n * Further discussion on Vike handling this natively: https://github.com/vikejs/vike/issues/2801\n */\nconst turbolinksBackButton = `addEventListener(\"popstate\", (e) => {\n if(e.state && e.state.turbolinks) window.location.reload();\n});`;\n\nexport default `<script>${\n turbolinksIOSCompat +\n turbolinksLoadEvent +\n disableVikeLinkInterception +\n turbolinksBackButton\n}</script>`;\n"],"mappings":";AAIA,IAAM,sBAAsB;AAG5B,IAAM,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAO5B,IAAM,8BAA8B;AAUpC,IAAM,uBAAuB;AAAA;AAAA;AAI7B,IAAO,wBAAQ,WACb,sBACA,sBACA,8BACA,oBACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../renderer/headHtmlBegin.ts"],"sourcesContent":["// We use headHtmlStart instead of +Head.tsx to avoid issues with userland usage of `+Head.clear.tsx` overwriting our handling\n\n// Register turbolinks global for ios to hook into\n// Also allows Turbolinks.visit / Turbolinks.controller.viewWillRender to be called before Turbolinks is started (Vike loads async)\nconst turbolinksIOSCompat = `window.Turbolinks = {controller:{restorationIdentifier: '',started:false,viewWillRender:(...a)=>{addEventListener(\"turbolinks:start\", () => {window.Turbolinks.controller.viewWillRender(...a)})}},visit:(...a)=>{addEventListener(\"turbolinks:start\", () => {window.Turbolinks.visit(...a)})}};`;\n\n/// emit turbolinks:load on DOMContentLoaded\nconst turbolinksLoadEvent = `addEventListener(\"DOMContentLoaded\", () => {\n const event = new Event(\"turbolinks:load\", { bubbles: true, cancelable: true });\n event.data = {url: window.location.href};\n document.dispatchEvent(event); \n});`;\n\n// Tells vike not to do link interception\nconst disableVikeLinkInterception = `window._disableAutomaticLinkInterception = true;`;\n\n/**\n * Hard reload when user navigates to a passthru turbolinks page.\n * Turbolinks navigates with history.pushState. When navigating passthru => bifrost (tracked scripts change), it reloads page.\n * Now on bifrost page, if user clicks back button, the browser sees the original navigation as initiated by pushState,\n * so the browser does not load the page. We detect this and force a reload.\n *\n * Further discussion on Vike handling this natively: https://github.com/vikejs/vike/issues/2801\n */\nconst turbolinksBackButton = `addEventListener(\"popstate\", (e) => {\n if(e.state && e.state.turbolinks) window.location.reload();\n});`;\n\nexport default `<script>${\n turbolinksIOSCompat +\n turbolinksLoadEvent +\n disableVikeLinkInterception +\n turbolinksBackButton\n}</script>`;\n"],"mappings":";AAIA,IAAM,sBAAsB;AAG5B,IAAM,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAO5B,IAAM,8BAA8B;AAUpC,IAAM,uBAAuB;AAAA;AAAA;AAI7B,IAAO,wBAAQ,WACb,sBACA,sBACA,8BACA,oBACF;","names":[]}
|