react/packages/shared/HostConfigWithNoHydration.js

53 lines
1.9 KiB
JavaScript
Raw Normal View History

Resolve host configs at build time (#12792) * Extract base Jest config This makes it easier to change the source config without affecting the build test config. * Statically import the host config This changes react-reconciler to import HostConfig instead of getting it through a function argument. Rather than start with packages like ReactDOM that want to inline it, I started with React Noop and ensured that *custom* renderers using react-reconciler package still work. To do this, I'm making HostConfig module in the reconciler look at a global variable by default (which, in case of the react-reconciler npm package, ends up being the host config argument in the top-level scope). This is still very broken. * Add scaffolding for importing an inlined renderer * Fix the build * ES exports for renderer methods * ES modules for host configs * Remove closures from the reconciler * Check each renderer's config with Flow * Fix uncovered Flow issue We know nextHydratableInstance doesn't get mutated inside this function, but Flow doesn't so it thinks it may be null. Help Flow. * Prettier * Get rid of enable*Reconciler flags They are not as useful anymore because for almost all cases (except third party renderers) we *know* whether it supports mutation or persistence. This refactoring means react-reconciler and react-reconciler/persistent third-party packages now ship the same thing. Not ideal, but this seems worth how simpler the code becomes. We can later look into addressing it by having a single toggle instead. * Prettier again * Fix Flow config creation issue * Fix imprecise Flow typing * Revert accidental changes
2018-05-19 18:29:11 +08:00
/**
* Copyright (c) Facebook, Inc. and its affiliates.
Resolve host configs at build time (#12792) * Extract base Jest config This makes it easier to change the source config without affecting the build test config. * Statically import the host config This changes react-reconciler to import HostConfig instead of getting it through a function argument. Rather than start with packages like ReactDOM that want to inline it, I started with React Noop and ensured that *custom* renderers using react-reconciler package still work. To do this, I'm making HostConfig module in the reconciler look at a global variable by default (which, in case of the react-reconciler npm package, ends up being the host config argument in the top-level scope). This is still very broken. * Add scaffolding for importing an inlined renderer * Fix the build * ES exports for renderer methods * ES modules for host configs * Remove closures from the reconciler * Check each renderer's config with Flow * Fix uncovered Flow issue We know nextHydratableInstance doesn't get mutated inside this function, but Flow doesn't so it thinks it may be null. Help Flow. * Prettier * Get rid of enable*Reconciler flags They are not as useful anymore because for almost all cases (except third party renderers) we *know* whether it supports mutation or persistence. This refactoring means react-reconciler and react-reconciler/persistent third-party packages now ship the same thing. Not ideal, but this seems worth how simpler the code becomes. We can later look into addressing it by having a single toggle instead. * Prettier again * Fix Flow config creation issue * Fix imprecise Flow typing * Revert accidental changes
2018-05-19 18:29:11 +08:00
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import invariant from 'shared/invariant';
Resolve host configs at build time (#12792) * Extract base Jest config This makes it easier to change the source config without affecting the build test config. * Statically import the host config This changes react-reconciler to import HostConfig instead of getting it through a function argument. Rather than start with packages like ReactDOM that want to inline it, I started with React Noop and ensured that *custom* renderers using react-reconciler package still work. To do this, I'm making HostConfig module in the reconciler look at a global variable by default (which, in case of the react-reconciler npm package, ends up being the host config argument in the top-level scope). This is still very broken. * Add scaffolding for importing an inlined renderer * Fix the build * ES exports for renderer methods * ES modules for host configs * Remove closures from the reconciler * Check each renderer's config with Flow * Fix uncovered Flow issue We know nextHydratableInstance doesn't get mutated inside this function, but Flow doesn't so it thinks it may be null. Help Flow. * Prettier * Get rid of enable*Reconciler flags They are not as useful anymore because for almost all cases (except third party renderers) we *know* whether it supports mutation or persistence. This refactoring means react-reconciler and react-reconciler/persistent third-party packages now ship the same thing. Not ideal, but this seems worth how simpler the code becomes. We can later look into addressing it by having a single toggle instead. * Prettier again * Fix Flow config creation issue * Fix imprecise Flow typing * Revert accidental changes
2018-05-19 18:29:11 +08:00
// Renderers that don't support hydration
// can re-export everything from this module.
function shim(...args: any) {
invariant(
false,
2018-11-10 02:17:19 +08:00
'The current renderer does not support hydration. ' +
Resolve host configs at build time (#12792) * Extract base Jest config This makes it easier to change the source config without affecting the build test config. * Statically import the host config This changes react-reconciler to import HostConfig instead of getting it through a function argument. Rather than start with packages like ReactDOM that want to inline it, I started with React Noop and ensured that *custom* renderers using react-reconciler package still work. To do this, I'm making HostConfig module in the reconciler look at a global variable by default (which, in case of the react-reconciler npm package, ends up being the host config argument in the top-level scope). This is still very broken. * Add scaffolding for importing an inlined renderer * Fix the build * ES exports for renderer methods * ES modules for host configs * Remove closures from the reconciler * Check each renderer's config with Flow * Fix uncovered Flow issue We know nextHydratableInstance doesn't get mutated inside this function, but Flow doesn't so it thinks it may be null. Help Flow. * Prettier * Get rid of enable*Reconciler flags They are not as useful anymore because for almost all cases (except third party renderers) we *know* whether it supports mutation or persistence. This refactoring means react-reconciler and react-reconciler/persistent third-party packages now ship the same thing. Not ideal, but this seems worth how simpler the code becomes. We can later look into addressing it by having a single toggle instead. * Prettier again * Fix Flow config creation issue * Fix imprecise Flow typing * Revert accidental changes
2018-05-19 18:29:11 +08:00
'This error is likely caused by a bug in React. ' +
'Please file an issue.',
);
}
// Hydration (when unsupported)
Partial Hydration (#14717) * Basic partial hydration test * Render comments around Suspense components We need this to be able to identify how far to skip ahead if we're not going to hydrate this subtree yet. * Add DehydratedSuspenseComponent type of work Will be used for Suspense boundaries that are left with their server rendered content intact. * Add comment node as hydratable instance type as placeholder for suspense * Skip past nodes within the Suspense boundary This lets us continue hydrating sibling nodes. * A dehydrated suspense boundary comment should be considered a sibling * Retry hydrating at offscreen pri or after ping if suspended * Enter hydration state when retrying dehydrated suspense boundary * Delete all children within a dehydrated suspense boundary when it's deleted * Delete server rendered content when props change before hydration completes * Make test internal * Wrap in act * Change SSR Fixture to use Partial Hydration This requires the enableSuspenseServerRenderer flag to be manually enabled for the build to work. * Changes to any parent Context forces clearing dehydrated content We mark dehydrated boundaries as having child work, since they might have components that read from the changed context. We check this in beginWork and if it does we treat it as if the input has changed (same as if props changes). * Wrap in feature flag * Treat Suspense boundaries without fallbacks as if not-boundaries These don't come into play for purposes of hydration. * Fix clearing of nested suspense boundaries * ping -> retry Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Typo Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Use didReceiveUpdate instead of manually comparing props * Leave comment for why it's ok to ignore the timeout
2019-02-12 13:25:44 +08:00
export type SuspenseInstance = mixed;
Resolve host configs at build time (#12792) * Extract base Jest config This makes it easier to change the source config without affecting the build test config. * Statically import the host config This changes react-reconciler to import HostConfig instead of getting it through a function argument. Rather than start with packages like ReactDOM that want to inline it, I started with React Noop and ensured that *custom* renderers using react-reconciler package still work. To do this, I'm making HostConfig module in the reconciler look at a global variable by default (which, in case of the react-reconciler npm package, ends up being the host config argument in the top-level scope). This is still very broken. * Add scaffolding for importing an inlined renderer * Fix the build * ES exports for renderer methods * ES modules for host configs * Remove closures from the reconciler * Check each renderer's config with Flow * Fix uncovered Flow issue We know nextHydratableInstance doesn't get mutated inside this function, but Flow doesn't so it thinks it may be null. Help Flow. * Prettier * Get rid of enable*Reconciler flags They are not as useful anymore because for almost all cases (except third party renderers) we *know* whether it supports mutation or persistence. This refactoring means react-reconciler and react-reconciler/persistent third-party packages now ship the same thing. Not ideal, but this seems worth how simpler the code becomes. We can later look into addressing it by having a single toggle instead. * Prettier again * Fix Flow config creation issue * Fix imprecise Flow typing * Revert accidental changes
2018-05-19 18:29:11 +08:00
export const supportsHydration = false;
export const canHydrateInstance = shim;
export const canHydrateTextInstance = shim;
Partial Hydration (#14717) * Basic partial hydration test * Render comments around Suspense components We need this to be able to identify how far to skip ahead if we're not going to hydrate this subtree yet. * Add DehydratedSuspenseComponent type of work Will be used for Suspense boundaries that are left with their server rendered content intact. * Add comment node as hydratable instance type as placeholder for suspense * Skip past nodes within the Suspense boundary This lets us continue hydrating sibling nodes. * A dehydrated suspense boundary comment should be considered a sibling * Retry hydrating at offscreen pri or after ping if suspended * Enter hydration state when retrying dehydrated suspense boundary * Delete all children within a dehydrated suspense boundary when it's deleted * Delete server rendered content when props change before hydration completes * Make test internal * Wrap in act * Change SSR Fixture to use Partial Hydration This requires the enableSuspenseServerRenderer flag to be manually enabled for the build to work. * Changes to any parent Context forces clearing dehydrated content We mark dehydrated boundaries as having child work, since they might have components that read from the changed context. We check this in beginWork and if it does we treat it as if the input has changed (same as if props changes). * Wrap in feature flag * Treat Suspense boundaries without fallbacks as if not-boundaries These don't come into play for purposes of hydration. * Fix clearing of nested suspense boundaries * ping -> retry Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Typo Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Use didReceiveUpdate instead of manually comparing props * Leave comment for why it's ok to ignore the timeout
2019-02-12 13:25:44 +08:00
export const canHydrateSuspenseInstance = shim;
export const isSuspenseInstancePending = shim;
export const isSuspenseInstanceFallback = shim;
export const registerSuspenseInstanceRetry = shim;
Resolve host configs at build time (#12792) * Extract base Jest config This makes it easier to change the source config without affecting the build test config. * Statically import the host config This changes react-reconciler to import HostConfig instead of getting it through a function argument. Rather than start with packages like ReactDOM that want to inline it, I started with React Noop and ensured that *custom* renderers using react-reconciler package still work. To do this, I'm making HostConfig module in the reconciler look at a global variable by default (which, in case of the react-reconciler npm package, ends up being the host config argument in the top-level scope). This is still very broken. * Add scaffolding for importing an inlined renderer * Fix the build * ES exports for renderer methods * ES modules for host configs * Remove closures from the reconciler * Check each renderer's config with Flow * Fix uncovered Flow issue We know nextHydratableInstance doesn't get mutated inside this function, but Flow doesn't so it thinks it may be null. Help Flow. * Prettier * Get rid of enable*Reconciler flags They are not as useful anymore because for almost all cases (except third party renderers) we *know* whether it supports mutation or persistence. This refactoring means react-reconciler and react-reconciler/persistent third-party packages now ship the same thing. Not ideal, but this seems worth how simpler the code becomes. We can later look into addressing it by having a single toggle instead. * Prettier again * Fix Flow config creation issue * Fix imprecise Flow typing * Revert accidental changes
2018-05-19 18:29:11 +08:00
export const getNextHydratableSibling = shim;
export const getFirstHydratableChild = shim;
export const hydrateInstance = shim;
export const hydrateTextInstance = shim;
export const hydrateSuspenseInstance = shim;
Partial Hydration (#14717) * Basic partial hydration test * Render comments around Suspense components We need this to be able to identify how far to skip ahead if we're not going to hydrate this subtree yet. * Add DehydratedSuspenseComponent type of work Will be used for Suspense boundaries that are left with their server rendered content intact. * Add comment node as hydratable instance type as placeholder for suspense * Skip past nodes within the Suspense boundary This lets us continue hydrating sibling nodes. * A dehydrated suspense boundary comment should be considered a sibling * Retry hydrating at offscreen pri or after ping if suspended * Enter hydration state when retrying dehydrated suspense boundary * Delete all children within a dehydrated suspense boundary when it's deleted * Delete server rendered content when props change before hydration completes * Make test internal * Wrap in act * Change SSR Fixture to use Partial Hydration This requires the enableSuspenseServerRenderer flag to be manually enabled for the build to work. * Changes to any parent Context forces clearing dehydrated content We mark dehydrated boundaries as having child work, since they might have components that read from the changed context. We check this in beginWork and if it does we treat it as if the input has changed (same as if props changes). * Wrap in feature flag * Treat Suspense boundaries without fallbacks as if not-boundaries These don't come into play for purposes of hydration. * Fix clearing of nested suspense boundaries * ping -> retry Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Typo Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Use didReceiveUpdate instead of manually comparing props * Leave comment for why it's ok to ignore the timeout
2019-02-12 13:25:44 +08:00
export const getNextHydratableInstanceAfterSuspenseInstance = shim;
Event Replaying (#16725) * Add Event Replaying Infra * Wire up Roots and Suspense boundaries, to retry events, after they commit * Replay discrete events in order in a separate scheduler callback * Add continuous events These events only replay their last target if the target is not yet hydrated. That way we don't have to wait for a previously hovered boundary before invoking the current target. * Enable tests from before These tests were written with replaying in mind and now we can properly enable them. * Unify replaying and dispatching * Mark system flags as a replay and pass to legacy events That way we can check if this is a replay and therefore needs a special case. One such special case is "mouseover" where we check the relatedTarget. * Eagerly listen to all replayable events To minimize breakages in a minor, I only do this for the new root APIs since replaying only matters there anyway. Only if hydrating. For Flare, I have to attach all active listeners since the current system has one DOM listener for each. In a follow up I plan on optimizing that by only attaching one if there's at least one active listener which would allow us to start with only passive and then upgrade. * Desperate attempt to save bytese * Add test for mouseover replaying We need to check if the "relatedTarget" is mounted due to how the old event system dispatches from the "out" event. * Fix for nested boundaries and suspense in root container This is a follow up to #16673 which didn't have a test because it wasn't observable yet. This shows that it had a bug. * Rename RESPONDER_EVENT_SYSTEM to PLUGIN_EVENT_SYSTEM
2019-09-24 02:21:10 +08:00
export const commitHydratedContainer = shim;
export const commitHydratedSuspenseInstance = shim;
Partial Hydration (#14717) * Basic partial hydration test * Render comments around Suspense components We need this to be able to identify how far to skip ahead if we're not going to hydrate this subtree yet. * Add DehydratedSuspenseComponent type of work Will be used for Suspense boundaries that are left with their server rendered content intact. * Add comment node as hydratable instance type as placeholder for suspense * Skip past nodes within the Suspense boundary This lets us continue hydrating sibling nodes. * A dehydrated suspense boundary comment should be considered a sibling * Retry hydrating at offscreen pri or after ping if suspended * Enter hydration state when retrying dehydrated suspense boundary * Delete all children within a dehydrated suspense boundary when it's deleted * Delete server rendered content when props change before hydration completes * Make test internal * Wrap in act * Change SSR Fixture to use Partial Hydration This requires the enableSuspenseServerRenderer flag to be manually enabled for the build to work. * Changes to any parent Context forces clearing dehydrated content We mark dehydrated boundaries as having child work, since they might have components that read from the changed context. We check this in beginWork and if it does we treat it as if the input has changed (same as if props changes). * Wrap in feature flag * Treat Suspense boundaries without fallbacks as if not-boundaries These don't come into play for purposes of hydration. * Fix clearing of nested suspense boundaries * ping -> retry Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Typo Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Use didReceiveUpdate instead of manually comparing props * Leave comment for why it's ok to ignore the timeout
2019-02-12 13:25:44 +08:00
export const clearSuspenseBoundary = shim;
export const clearSuspenseBoundaryFromContainer = shim;
Resolve host configs at build time (#12792) * Extract base Jest config This makes it easier to change the source config without affecting the build test config. * Statically import the host config This changes react-reconciler to import HostConfig instead of getting it through a function argument. Rather than start with packages like ReactDOM that want to inline it, I started with React Noop and ensured that *custom* renderers using react-reconciler package still work. To do this, I'm making HostConfig module in the reconciler look at a global variable by default (which, in case of the react-reconciler npm package, ends up being the host config argument in the top-level scope). This is still very broken. * Add scaffolding for importing an inlined renderer * Fix the build * ES exports for renderer methods * ES modules for host configs * Remove closures from the reconciler * Check each renderer's config with Flow * Fix uncovered Flow issue We know nextHydratableInstance doesn't get mutated inside this function, but Flow doesn't so it thinks it may be null. Help Flow. * Prettier * Get rid of enable*Reconciler flags They are not as useful anymore because for almost all cases (except third party renderers) we *know* whether it supports mutation or persistence. This refactoring means react-reconciler and react-reconciler/persistent third-party packages now ship the same thing. Not ideal, but this seems worth how simpler the code becomes. We can later look into addressing it by having a single toggle instead. * Prettier again * Fix Flow config creation issue * Fix imprecise Flow typing * Revert accidental changes
2018-05-19 18:29:11 +08:00
export const didNotMatchHydratedContainerTextInstance = shim;
export const didNotMatchHydratedTextInstance = shim;
export const didNotHydrateContainerInstance = shim;
export const didNotHydrateInstance = shim;
export const didNotFindHydratableContainerInstance = shim;
export const didNotFindHydratableContainerTextInstance = shim;
Partial Hydration (#14717) * Basic partial hydration test * Render comments around Suspense components We need this to be able to identify how far to skip ahead if we're not going to hydrate this subtree yet. * Add DehydratedSuspenseComponent type of work Will be used for Suspense boundaries that are left with their server rendered content intact. * Add comment node as hydratable instance type as placeholder for suspense * Skip past nodes within the Suspense boundary This lets us continue hydrating sibling nodes. * A dehydrated suspense boundary comment should be considered a sibling * Retry hydrating at offscreen pri or after ping if suspended * Enter hydration state when retrying dehydrated suspense boundary * Delete all children within a dehydrated suspense boundary when it's deleted * Delete server rendered content when props change before hydration completes * Make test internal * Wrap in act * Change SSR Fixture to use Partial Hydration This requires the enableSuspenseServerRenderer flag to be manually enabled for the build to work. * Changes to any parent Context forces clearing dehydrated content We mark dehydrated boundaries as having child work, since they might have components that read from the changed context. We check this in beginWork and if it does we treat it as if the input has changed (same as if props changes). * Wrap in feature flag * Treat Suspense boundaries without fallbacks as if not-boundaries These don't come into play for purposes of hydration. * Fix clearing of nested suspense boundaries * ping -> retry Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Typo Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Use didReceiveUpdate instead of manually comparing props * Leave comment for why it's ok to ignore the timeout
2019-02-12 13:25:44 +08:00
export const didNotFindHydratableContainerSuspenseInstance = shim;
Resolve host configs at build time (#12792) * Extract base Jest config This makes it easier to change the source config without affecting the build test config. * Statically import the host config This changes react-reconciler to import HostConfig instead of getting it through a function argument. Rather than start with packages like ReactDOM that want to inline it, I started with React Noop and ensured that *custom* renderers using react-reconciler package still work. To do this, I'm making HostConfig module in the reconciler look at a global variable by default (which, in case of the react-reconciler npm package, ends up being the host config argument in the top-level scope). This is still very broken. * Add scaffolding for importing an inlined renderer * Fix the build * ES exports for renderer methods * ES modules for host configs * Remove closures from the reconciler * Check each renderer's config with Flow * Fix uncovered Flow issue We know nextHydratableInstance doesn't get mutated inside this function, but Flow doesn't so it thinks it may be null. Help Flow. * Prettier * Get rid of enable*Reconciler flags They are not as useful anymore because for almost all cases (except third party renderers) we *know* whether it supports mutation or persistence. This refactoring means react-reconciler and react-reconciler/persistent third-party packages now ship the same thing. Not ideal, but this seems worth how simpler the code becomes. We can later look into addressing it by having a single toggle instead. * Prettier again * Fix Flow config creation issue * Fix imprecise Flow typing * Revert accidental changes
2018-05-19 18:29:11 +08:00
export const didNotFindHydratableInstance = shim;
export const didNotFindHydratableTextInstance = shim;
Partial Hydration (#14717) * Basic partial hydration test * Render comments around Suspense components We need this to be able to identify how far to skip ahead if we're not going to hydrate this subtree yet. * Add DehydratedSuspenseComponent type of work Will be used for Suspense boundaries that are left with their server rendered content intact. * Add comment node as hydratable instance type as placeholder for suspense * Skip past nodes within the Suspense boundary This lets us continue hydrating sibling nodes. * A dehydrated suspense boundary comment should be considered a sibling * Retry hydrating at offscreen pri or after ping if suspended * Enter hydration state when retrying dehydrated suspense boundary * Delete all children within a dehydrated suspense boundary when it's deleted * Delete server rendered content when props change before hydration completes * Make test internal * Wrap in act * Change SSR Fixture to use Partial Hydration This requires the enableSuspenseServerRenderer flag to be manually enabled for the build to work. * Changes to any parent Context forces clearing dehydrated content We mark dehydrated boundaries as having child work, since they might have components that read from the changed context. We check this in beginWork and if it does we treat it as if the input has changed (same as if props changes). * Wrap in feature flag * Treat Suspense boundaries without fallbacks as if not-boundaries These don't come into play for purposes of hydration. * Fix clearing of nested suspense boundaries * ping -> retry Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Typo Co-Authored-By: sebmarkbage <sebastian@calyptus.eu> * Use didReceiveUpdate instead of manually comparing props * Leave comment for why it's ok to ignore the timeout
2019-02-12 13:25:44 +08:00
export const didNotFindHydratableSuspenseInstance = shim;