Skip to content

Commit

Permalink
Update to turbo 8.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemanrubia committed Oct 15, 2024
1 parent 8c681dd commit 52727cb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 33 deletions.
47 changes: 27 additions & 20 deletions app/assets/javascripts/turbo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Turbo 8.0.6
Turbo 8.0.12
Copyright © 2024 37signals LLC
*/
(function(prototype) {
Expand Down Expand Up @@ -181,7 +181,7 @@ function activateScriptElement(element) {
return element;
} else {
const createdScriptElement = document.createElement("script");
const cspNonce = getMetaContent("csp-nonce");
const cspNonce = getCspNonce();
if (cspNonce) {
createdScriptElement.nonce = cspNonce;
}
Expand Down Expand Up @@ -353,6 +353,14 @@ function getMetaContent(name) {
return element && element.content;
}

function getCspNonce() {
const element = getMetaElement("csp-nonce");
if (element) {
const {nonce: nonce, content: content} = element;
return nonce == "" ? content : nonce;
}
}

function setMetaContent(name, content) {
let element = getMetaElement(name);
if (!element) {
Expand Down Expand Up @@ -1531,12 +1539,13 @@ function createPlaceholderForPermanentElement(permanentElement) {

class Renderer {
#activeElement=null;
constructor(currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) {
static renderElement(currentElement, newElement) {}
constructor(currentSnapshot, newSnapshot, isPreview, willRender = true) {
this.currentSnapshot = currentSnapshot;
this.newSnapshot = newSnapshot;
this.isPreview = isPreview;
this.willRender = willRender;
this.renderElement = renderElement;
this.renderElement = this.constructor.renderElement;
this.promise = new Promise(((resolve, reject) => this.resolvingFunctions = {
resolve: resolve,
reject: reject
Expand Down Expand Up @@ -2289,6 +2298,9 @@ class MorphingFrameRenderer extends FrameRenderer {
});
morphChildren(currentElement, newElement);
}
async preservingPermanentElements(callback) {
return await callback();
}
}

class ProgressBar {
Expand Down Expand Up @@ -2380,8 +2392,9 @@ class ProgressBar {
const element = document.createElement("style");
element.type = "text/css";
element.textContent = ProgressBar.defaultCSS;
if (this.cspNonce) {
element.nonce = this.cspNonce;
const cspNonce = getCspNonce();
if (cspNonce) {
element.nonce = cspNonce;
}
return element;
}
Expand All @@ -2390,9 +2403,6 @@ class ProgressBar {
element.className = "turbo-progress-bar";
return element;
}
get cspNonce() {
return getMetaContent("csp-nonce");
}
}

class HeadSnapshot extends Snapshot {
Expand Down Expand Up @@ -4013,7 +4023,7 @@ class PageView extends View {
renderPage(snapshot, isPreview = false, willRender = true, visit) {
const shouldMorphPage = this.isPageRefresh(visit) && this.snapshot.shouldMorphPage;
const rendererClass = shouldMorphPage ? MorphingPageRenderer : PageRenderer;
const renderer = new rendererClass(this.snapshot, snapshot, rendererClass.renderElement, isPreview, willRender);
const renderer = new rendererClass(this.snapshot, snapshot, isPreview, willRender);
if (!renderer.shouldRender) {
this.forceReloaded = true;
} else {
Expand All @@ -4023,7 +4033,7 @@ class PageView extends View {
}
renderError(snapshot, visit) {
visit?.changeHistory();
const renderer = new ErrorRenderer(this.snapshot, snapshot, ErrorRenderer.renderElement, false);
const renderer = new ErrorRenderer(this.snapshot, snapshot, false);
return this.render(renderer);
}
clearSnapshotCache() {
Expand Down Expand Up @@ -4589,6 +4599,7 @@ class FrameController {
#connected=false;
#hasBeenLoaded=false;
#ignoredAttributes=new Set;
#shouldMorphFrame=false;
action=null;
constructor(element) {
this.element = element;
Expand Down Expand Up @@ -4636,14 +4647,8 @@ class FrameController {
}
}
sourceURLReloaded() {
if (this.element.shouldReloadWithMorph) {
this.element.addEventListener("turbo:before-frame-render", (({detail: detail}) => {
detail.render = MorphingFrameRenderer.renderElement;
}), {
once: true
});
}
const {src: src} = this.element;
const {refresh: refresh, src: src} = this.element;
this.#shouldMorphFrame = src && refresh === "morph";
this.element.removeAttribute("complete");
this.element.src = null;
this.element.src = src;
Expand Down Expand Up @@ -4681,6 +4686,7 @@ class FrameController {
}
}
} finally {
this.#shouldMorphFrame = false;
this.fetchResponseLoaded = () => Promise.resolve();
}
}
Expand Down Expand Up @@ -4793,9 +4799,10 @@ class FrameController {
};
async #loadFrameResponse(fetchResponse, document) {
const newFrameElement = await this.extractForeignFrameElement(document.body);
const rendererClass = this.#shouldMorphFrame ? MorphingFrameRenderer : FrameRenderer;
if (newFrameElement) {
const snapshot = new Snapshot(newFrameElement);
const renderer = new FrameRenderer(this, this.view.snapshot, snapshot, FrameRenderer.renderElement, false, false);
const renderer = new rendererClass(this, this.view.snapshot, snapshot, false, false);
if (this.view.renderPromise) await this.view.renderPromise;
this.changeHistory();
await this.view.render(renderer);
Expand Down
12 changes: 6 additions & 6 deletions app/assets/javascripts/turbo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/turbo.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hotwired/turbo-rails",
"version": "8.0.11",
"version": "8.0.12",
"description": "The speed of a single-page web application without having to write any JavaScript",
"module": "app/javascript/turbo/index.js",
"main": "app/assets/javascripts/turbo.js",
Expand All @@ -19,7 +19,7 @@
"release": "npm publish && git commit -am \"$npm_package_name v$npm_package_version\" && git push"
},
"dependencies": {
"@hotwired/turbo": "^8.0.6",
"@hotwired/turbo": "^8.0.12",
"@rails/actioncable": "^7.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
chalk "^2.4.2"
js-tokens "^4.0.0"

"@hotwired/turbo@^8.0.6":
version "8.0.6"
resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-8.0.6.tgz#d7c546f7700f18ebfe4d1b106e03c9ed1bb22887"
integrity sha512-mwZRfwcJ4yatUnW5tcCY9NDvo0kjuuLQF/y8pXigHhS+c/JY/ccNluVyuERR9Sraqx0qdpenkO3pNeSWz1mE3w==
"@hotwired/turbo@^8.0.12":
version "8.0.12"
resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-8.0.12.tgz#50aa8345d7f62402680c6d2d9814660761837001"
integrity sha512-l3BiQRkD7qrnQv6ms6sqPLczvwbQpXt5iAVwjDvX0iumrz6yEonQkNAzNjeDX25/OJMFDTxpHjkJZHGpM9ikWw==

"@jridgewell/gen-mapping@^0.3.0":
version "0.3.3"
Expand Down

0 comments on commit 52727cb

Please sign in to comment.