react-on-rails
Advanced tools
Comparing version
@@ -1,5 +0,13 @@ | ||
| # The MIT License (MIT) | ||
| # Licensing | ||
| Copyright (c) 2017, 2018 Justin Gordon and ShakaCode, http://www.shakacode.com | ||
| - **Core**: MIT (this file) | ||
| - **Pro**: see [REACT-ON-RAILS-PRO-LICENSE.md](./REACT-ON-RAILS-PRO-LICENSE.md) | ||
| --- | ||
| # MIT License | ||
| Copyright (c) 2017, 2018 Justin Gordon and ShakaCode | ||
| Copyright (c) 2015–2025 ShakaCode, LLC | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
@@ -15,2 +23,6 @@ of this software and associated documentation files (the "Software"), to deal | ||
| --- | ||
| ## Disclaimer | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
@@ -21,3 +33,3 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
@@ -10,3 +10,6 @@ /* eslint-disable max-classes-per-file */ | ||
| import * as ComponentRegistry from "./ComponentRegistry.js"; | ||
| import { onPageLoaded } from "./pageLifecycle.js"; | ||
| const REACT_ON_RAILS_STORE_ATTRIBUTE = 'data-js-react-on-rails-store'; | ||
| const IMMEDIATE_HYDRATION_PRO_WARNING = "[REACT ON RAILS] The 'immediate_hydration' feature requires a React on Rails Pro license. " + | ||
| 'Please visit https://shakacode.com/react-on-rails-pro to get a license.'; | ||
| async function delegateToRenderer(componentObj, props, railsContext, domNodeId, trace) { | ||
@@ -49,2 +52,14 @@ const { name, component, isRenderer } = componentObj; | ||
| async render(el, railsContext) { | ||
| const isImmediateHydrationRequested = el.getAttribute('data-immediate-hydration') === 'true'; | ||
| const hasProLicense = railsContext.rorPro; | ||
| // Handle immediate_hydration feature usage without Pro license | ||
| if (isImmediateHydrationRequested && !hasProLicense) { | ||
| console.warn(IMMEDIATE_HYDRATION_PRO_WARNING); | ||
| // Fallback to standard behavior: wait for page load before hydrating | ||
| if (document.readyState === 'loading') { | ||
| await new Promise((resolve) => { | ||
| onPageLoaded(resolve); | ||
| }); | ||
| } | ||
| } | ||
| // This must match lib/react_on_rails/helper.rb | ||
@@ -51,0 +66,0 @@ const name = el.getAttribute('data-component-name') || ''; |
@@ -17,8 +17,9 @@ import { debugTurbolinks, turbolinksInstalled, turbolinksSupported, turboInstalled, turbolinksVersion5, } from "./turbolinksUtils.js"; | ||
| } | ||
| function setupTurbolinksEventListeners() { | ||
| function setupPageNavigationListeners() { | ||
| // Install listeners when running on the client (browser). | ||
| // We must do this check for turbolinks AFTER the document is loaded because we load the | ||
| // We must check for navigation libraries AFTER the document is loaded because we load the | ||
| // Webpack bundles first. | ||
| if ((!turbolinksInstalled() || !turbolinksSupported()) && !turboInstalled()) { | ||
| debugTurbolinks('NOT USING TURBOLINKS: calling reactOnRailsPageLoaded'); | ||
| const hasNavigationLibrary = (turbolinksInstalled() && turbolinksSupported()) || turboInstalled(); | ||
| if (!hasNavigationLibrary) { | ||
| debugTurbolinks('NO NAVIGATION LIBRARY: running page loaded callbacks immediately'); | ||
| runPageLoadedCallbacks(); | ||
@@ -28,3 +29,3 @@ return; | ||
| if (turboInstalled()) { | ||
| debugTurbolinks('USING TURBO: document added event listeners turbo:before-render and turbo:render.'); | ||
| debugTurbolinks('TURBO DETECTED: adding event listeners for turbo:before-render and turbo:render.'); | ||
| document.addEventListener('turbo:before-render', runPageUnloadedCallbacks); | ||
@@ -35,3 +36,3 @@ document.addEventListener('turbo:render', runPageLoadedCallbacks); | ||
| else if (turbolinksVersion5()) { | ||
| debugTurbolinks('USING TURBOLINKS 5: document added event listeners turbolinks:before-render and turbolinks:render.'); | ||
| debugTurbolinks('TURBOLINKS 5 DETECTED: adding event listeners for turbolinks:before-render and turbolinks:render.'); | ||
| document.addEventListener('turbolinks:before-render', runPageUnloadedCallbacks); | ||
@@ -42,3 +43,3 @@ document.addEventListener('turbolinks:render', runPageLoadedCallbacks); | ||
| else { | ||
| debugTurbolinks('USING TURBOLINKS 2: document added event listeners page:before-unload and page:change.'); | ||
| debugTurbolinks('TURBOLINKS 2 DETECTED: adding event listeners for page:before-unload and page:change.'); | ||
| document.addEventListener('page:before-unload', runPageUnloadedCallbacks); | ||
@@ -48,15 +49,15 @@ document.addEventListener('page:change', runPageLoadedCallbacks); | ||
| } | ||
| let isEventListenerInitialized = false; | ||
| let isPageLifecycleInitialized = false; | ||
| function initializePageEventListeners() { | ||
| if (typeof window === 'undefined') | ||
| return; | ||
| if (isEventListenerInitialized) { | ||
| if (isPageLifecycleInitialized) { | ||
| return; | ||
| } | ||
| isEventListenerInitialized = true; | ||
| if (document.readyState === 'complete') { | ||
| setupTurbolinksEventListeners(); | ||
| isPageLifecycleInitialized = true; | ||
| if (document.readyState !== 'loading') { | ||
| setupPageNavigationListeners(); | ||
| } | ||
| else { | ||
| document.addEventListener('DOMContentLoaded', setupTurbolinksEventListeners); | ||
| document.addEventListener('DOMContentLoaded', setupPageNavigationListeners); | ||
| } | ||
@@ -63,0 +64,0 @@ } |
| { | ||
| "name": "react-on-rails", | ||
| "version": "15.0.0", | ||
| "version": "16.0.0", | ||
| "description": "react-on-rails JavaScript for react_on_rails Ruby gem", | ||
@@ -5,0 +5,0 @@ "main": "node_package/lib/ReactOnRails.full.js", |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
232378
0.48%3778
0.43%