1+ /**
2+ * This argument is empty. This is for consisntency so `pluginOptions` is always second argument.
3+ * @typedef {undefined } emptyArg
4+ */
5+
6+ /**
7+ * Object containing options defined in `gatsby-config.js`
8+ * @typedef {object } pluginOptions
9+ */
10+
111/**
212 * Called when the Gatsby browser runtime first starts.
13+ * @param {emptyArg } _
14+ * @param {pluginOptions } pluginOptions
315 * @example
416 * exports.onClientEntry = () => {
517 * console.log("We've started!")
@@ -10,6 +22,8 @@ exports.onClientEntry = true
1022
1123/**
1224 * Called when the initial (but not subsequent) render of Gatsby App is done on the client.
25+ * @param {emptyArg } _
26+ * @param {pluginOptions } pluginOptions
1327 * @example
1428 * exports.onInitialClientRender = () => {
1529 * console.log("ReactDOM.render has executed")
@@ -22,6 +36,7 @@ exports.onInitialClientRender = true
2236 * @param {object } $0
2337 * @param {object } $0.location A location object
2438 * @param {object|null } $0.prevLocation The previous location object
39+ * @param {pluginOptions } pluginOptions
2540 * @example
2641 * exports.onPreRouteUpdate = ({ location, prevLocation }) => {
2742 * console.log("Gatsby started to change location to", location.pathname)
@@ -35,6 +50,7 @@ exports.onPreRouteUpdate = true
3550 * @param {object } $0
3651 * @param {object } $0.location A location object
3752 * @param {object } $0.action The "action" that caused the route change
53+ * @param {pluginOptions } pluginOptions
3854 * @example
3955 * exports.onRouteUpdateDelayed = () => {
4056 * console.log("We can show loading indicator now")
@@ -47,6 +63,7 @@ exports.onRouteUpdateDelayed = true
4763 * @param {object } $0
4864 * @param {object } $0.location A location object
4965 * @param {object|null } $0.prevLocation The previous location object
66+ * @param {pluginOptions } pluginOptions
5067 * @example
5168 * exports.onRouteUpdate = ({ location, prevLocation }) => {
5269 * console.log('new pathname', location.pathname)
@@ -78,6 +95,7 @@ exports.onRouteUpdate = true
7895 * coordinates to scroll to, a string of the `id` or `name` of an element to
7996 * scroll to, `false` to not update the scroll position, or `true` for the
8097 * default behavior.
98+ * @param {pluginOptions } pluginOptions
8199 * @example
82100 * exports.shouldUpdateScroll = ({
83101 * routerProps: { location },
@@ -95,17 +113,22 @@ exports.shouldUpdateScroll = true
95113
96114/**
97115 * Allow a plugin to register a Service Worker. Should be a function that returns true.
116+ * @param {emptyArg } _
117+ * @param {pluginOptions } pluginOptions
118+ * @returns {boolean } Should Gatsby register `/sw.js` service worker
98119 * @example
99120 * exports.registerServiceWorker = () => true
100121 */
101122exports . registerServiceWorker = true
102123
103124/**
104- * Allow a plugin to replace the page component renderer. This api runner can be used to
105- * implement page transitions. See https://github.com/gatsbyjs/gatsby/tree/master/examples/using- page-transitions for an example of this .
125+ * Allow a plugin to replace the page component renderer.
126+ * @deprecated Use [wrapPageElement](#wrapPageElement) to decorate page element .
106127 * @param {object } $0
107128 * @param {object } $0.props The props of the page.
108129 * @param {object } $0.loader The gatsby loader.
130+ * @param {pluginOptions } pluginOptions
131+ * @returns {ReactNode } Replaced default page renderer
109132 */
110133exports . replaceComponentRenderer = true
111134
@@ -119,6 +142,8 @@ exports.replaceComponentRenderer = true
119142 * @param {object } $0
120143 * @param {ReactNode } $0.element The "Page" React Element built by Gatsby.
121144 * @param {object } $0.props Props object used by page.
145+ * @param {pluginOptions } pluginOptions
146+ * @returns {ReactNode } Wrapped element
122147 * @example
123148 * import React from "react"
124149 * import Layout from "./src/components/layout"
@@ -140,6 +165,8 @@ exports.wrapPageElement = true
140165 * _Note:_ [There is equivalent hook in SSR API](/docs/ssr-apis/#wrapRootElement)
141166 * @param {object } $0
142167 * @param {ReactNode } $0.element The "Root" React Element built by Gatsby.
168+ * @param {pluginOptions } pluginOptions
169+ * @returns {ReactNode } Wrapped element
143170 * @example
144171 * import React from "react"
145172 * import { Provider } from "react-redux"
@@ -163,6 +190,7 @@ exports.wrapRootElement = true
163190 * @param {object } $0
164191 * @param {string } $0.pathname The pathname whose resources should now be prefetched
165192 * @param {function } $0.getResourcesForPathname Function for fetching resources related to pathname
193+ * @param {pluginOptions } pluginOptions
166194 */
167195exports . onPrefetchPathname = true
168196
@@ -172,21 +200,28 @@ exports.onPrefetchPathname = true
172200 * @param {object } $0
173201 * @param {string } $0.pathname The pathname whose resources have now been prefetched
174202 * @param {function } $0.getResourceURLsForPathname Function for fetching URLs for resources related to the pathname
203+ * @param {pluginOptions } pluginOptions
175204 */
176205exports . onPostPrefetchPathname = true
177206
178207/**
179208 * Plugins can take over prefetching logic. If they do, they should call this
180209 * to disable the now duplicate core prefetching logic.
210+ * @param {emptyArg } _
211+ * @param {pluginOptions } pluginOptions
212+ * @returns {boolean } Should disable core prefetching
181213 * @example
182214 * exports.disableCorePrefetching = () => true
183215 */
184216exports . disableCorePrefetching = true
185217
186218/**
187- * Allow a plugin to replace the ReactDOM.render function call by a custom renderer.
188- * This method takes no param and should return a function with same signature as ReactDOM.render()
189- * Note it's very important to call the callback after rendering, otherwise Gatsby will not be able to call `onInitialClientRender`
219+ * Allow a plugin to replace the `ReactDOM.render`/`ReactDOM.hydrate` function call by a custom renderer.
220+ * @param {emptyArg } _
221+ * @param {pluginOptions } pluginOptions
222+ * @returns {Function } This method should return a function with same signature as `ReactDOM.render()`
223+ *
224+ * _Note:_ it's very important to call the `callback` after rendering, otherwise Gatsby will not be able to call `onInitialClientRender`
190225 * @example
191226 * exports.replaceHydrateFunction = () => {
192227 * return (element, container, callback) => {
@@ -201,13 +236,15 @@ exports.replaceHydrateFunction = true
201236 * Inform plugins when a service worker has been installed.
202237 * @param {object } $0
203238 * @param {object } $0.serviceWorker The service worker instance.
239+ * @param {pluginOptions } pluginOptions
204240 */
205241exports . onServiceWorkerInstalled = true
206242
207243/**
208244 * Inform plugins of when a service worker has an update available.
209245 * @param {object } $0
210246 * @param {object } $0.serviceWorker The service worker instance.
247+ * @param {pluginOptions } pluginOptions
211248 */
212249exports . onServiceWorkerUpdateFound = true
213250
@@ -216,19 +253,22 @@ exports.onServiceWorkerUpdateFound = true
216253 * and the page is ready to reload to apply changes.
217254 * @param {object } $0
218255 * @param {object } $0.serviceWorker The service worker instance.
256+ * @param {pluginOptions } pluginOptions
219257 */
220258exports . onServiceWorkerUpdateReady = true
221259
222260/**
223261 * Inform plugins when a service worker has become active.
224262 * @param {object } $0
225263 * @param {object } $0.serviceWorker The service worker instance.
264+ * @param {pluginOptions } pluginOptions
226265 */
227266exports . onServiceWorkerActive = true
228267
229268/**
230269 * Inform plugins when a service worker is redundant.
231270 * @param {object } $0
232271 * @param {object } $0.serviceWorker The service worker instance.
272+ * @param {pluginOptions } pluginOptions
233273 */
234274exports . onServiceWorkerRedundant = true
0 commit comments