From 018812ca5de9963a8354f934230499c770e45377 Mon Sep 17 00:00:00 2001 From: Mendel Kramer Date: Wed, 6 Jun 2018 16:35:28 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Document=20integrating=20with=20?= =?UTF-8?q?Turbolinks=20when=20imported=20with=20Webpacker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ci skip] resolves #899 --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 5b2260be..9e69f717 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,19 @@ ReactRailsUJS.detectEvents() For example, if `Turbolinks` is loaded _after_ `ReactRailsUJS`, you'll need to call this again. This function removes previous handlers before adding new ones, so it's safe to call as often as needed. +If `Turbolinks` is `import`ed via Webpacker (and thus not available globally), `ReactRailsUJS` will be unable to locate it. To fix this, you can temporarily add it to the global namespace: + +```js +// Order is particular. First start Turbolinks: +Turbolinks.start(); +// Add Turbolinks to the global namespace: +window.Turbolinks = Turbolinks; +// Remove previous event handlers and add new ones: +ReactRailsUJS.detectEvents(); +// (Optional) Clean up global namespace: +delete window.Turbolinks; +``` + ### `getConstructor` Components are loaded with `ReactRailsUJS.getConstructor(className)`. This function has two built-in implementations: