1import { injectQuery as __vite__injectQuery } from "/@vite/client"; 2const exports = {} 3/** 4 * @license React 5 * react-refresh-runtime.development.js 6 * 7 * Copyright (c) Facebook, Inc. and its affiliates. 8 * 9 * This source code is licensed under the MIT license found in the 10 * LICENSE file in the root directory of this source tree. 11 */ 12 13'use strict'; 14 15if ("development" !== "production") { 16 (function() { 17'use strict'; 18 19// ATTENTION 20var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref'); 21var REACT_MEMO_TYPE = Symbol.for('react.memo'); 22 23var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; // We never remove these associations. 24// It's OK to reference families, but use WeakMap/Set for types. 25 26var allFamiliesByID = new Map(); 27var allFamiliesByType = new PossiblyWeakMap(); 28var allSignaturesByType = new PossiblyWeakMap(); // This WeakMap is read by React, so we only put families 29// that have actually been edited here. This keeps checks fast. 30// $FlowIssue 31 32var updatedFamiliesByType = new PossiblyWeakMap(); // This is cleared on every performReactRefresh() call. 33// It is an array of [Family, NextType] tuples. 34 35var pendingUpdates = []; // This is injected by the renderer via DevTools global hook. 36 37var helpersByRendererID = new Map(); 38var helpersByRoot = new Map(); // We keep track of mounted roots so we can schedule updates. 39 40var mountedRoots = new Set(); // If a root captures an error, we remember it so we can retry on edit. 41 42var failedRoots = new Set(); // In environments that support WeakMap, we also remember the last element for every root. 43// It needs to be weak because we do this even for roots that failed to mount. 44// If there is no WeakMap, we won't attempt to do retrying. 45// $FlowIssue 46 47var rootElements = // $FlowIssue 48typeof WeakMap === 'function' ? new WeakMap() : null; 49var isPerformingRefresh = false; 50 51function computeFullKey(signature) { 52 if (signature.fullKey !== null) { 53 return signature.fullKey; 54 } 55 56 var fullKey = signature.ownKey; 57 var hooks; 58 59 try { 60 hooks = signature.getCustomHooks(); 61 } catch (err) {
62 // This can happen in an edge case, e.g. if expression like Foo.useSomething 63 // depends on Foo which is lazily initialized during rendering. 64 // In that case just assume we'll have to remount. 65 signature.forceReset = true; 66 signature.fullKey = fullKey; 67 return fullKey; 68 } 69 70 for (var i = 0; i < hooks.length; i++) { 71 var hook = hooks[i]; 72 73 if (typeof hook !== 'function') { 74 // Something's wrong. Assume we need to remount. 75 signature.forceReset = true; 76 signature.fullKey = fullKey; 77 return fullKey; 78 } 79 80 var nestedHookSignature = allSignaturesByType.get(hook); 81 82 if (nestedHookSignature === undefined) { 83 // No signature means Hook wasn't in the source code, e.g. in a library. 84 // We'll skip it because we can assume it won't change during this session. 85 continue; 86 } 87 88 var nestedHookKey = computeFullKey(nestedHookSignature); 89 90 if (nestedHookSignature.forceReset) { 91 signature.forceReset = true; 92 } 93 94 fullKey += '\n---\n' + nestedHookKey; 95 } 96 97 signature.fullKey = fullKey; 98 return fullKey; 99} 100 101function haveEqualSignatures(prevType, nextType) { 102 var prevSignature = allSignaturesByType.get(prevType); 103 var nextSignature = allSignaturesByType.get(nextType); 104 105 if (prevSignature === undefined && nextSignature === undefined) { 106 return true; 107 } 108 109 if (prevSignature === undefined || nextSignature === undefined) { 110 return false; 111 } 112 113 if (computeFullKey(prevSignature) !== computeFullKey(nextSignature)) { 114 return false; 115 } 116 117 if (nextSignature.forceReset) { 118 return false; 119 } 120 121 return true; 122} 123 124function isReactClass(type) { 125 return type.prototype && type.prototype.isReactComponent; 126} 127 128function canPreserveStateBetween(prevType, nextType) { 129 if (isReactClass(prevType) || isReactClass(nextType)) { 130 return false; 131 } 132 133 if (haveEqualSignatures(prevType, nextType)) { 134 return true; 135 } 136 137 return false; 138} 139 140function resolveFamily(type) { 141 // Only check updated types to keep lookups fast. 142 return updatedFamiliesByType.get(type); 143} // If we didn't care about IE11, we could use new Map/Set(iterable). 144 145 146function cloneMap(map) { 147 var clone = new Map(); 148 map.forEach(function (value, key) { 149 clone.set(key, value); 150 }); 151 return clone; 152} 153 154function cloneSet(set) { 155 var clone = new Set(); 156 set.forEach(function (value) { 157 clone.add(value); 158 }); 159 return clone; 160} // This is a safety mechanism to protect against rogue getters and Proxies. 161 162 163function getProperty(object, property) { 164 try { 165 return object[property]; 166 } catch (err) { 167 // Intentionally ignore. 168 return undefined; 169 } 170} 171 172function performReactRefresh() { 173 174 if (pendingUpdates.length === 0) { 175 return null; 176 } 177 178 if (isPerformingRefresh) { 179 return null; 180 } 181 182 isPerformingRefresh = true; 183 184 try { 185 var staleFamilies = new Set(); 186 var updatedFamilies = new Set(); 187 var updates = pendingUpdates; 188 pendingUpdates = []; 189 updates.forEach(function (_ref) { 190 var family = _ref[0], 191 nextType = _ref[1]; 192 // Now that we got a real edit, we can create associations 193 // that will be read by the React reconciler. 194 var prevType = family.current; 195 updatedFamiliesByType.set(prevType, family); 196 updatedFamiliesByType.set(nextType, family); 197 family.current = nextType; // Determine whether this should be a re-render or a re-mount. 198 199 if (canPreserveStateBetween(prevType, nextType)) { 200 updatedFamilies.add(family); 201 } else { 202 staleFamilies.add(family); 203 } 204 }); // TODO: rename these fields to something more meaningful. 205 206 var update = { 207 updatedFamilies: updatedFamilies, 208 // Families that will re-render preserving state 209 staleFamilies: staleFamilies // Families that will be remounted 210 211 }; 212 helpersByRendererID.forEach(function (helpers) { 213 // Even if there are no roots, set the handler on first update. 214 // This ensures that if *new* roots are mounted, they'll use the resolve handler. 215 helpers.setRefreshHandler(resolveFamily); 216 }); 217 var didError = false; 218 var firstError = null; // We snapshot maps and sets that are mutated during commits. 219 // If we don't do this, there is a risk they will be mutated while
220 // we iterate over them. For example, trying to recover a failed root 221 // may cause another root to be added to the failed list -- an infinite loop. 222 223 var failedRootsSnapshot = cloneSet(failedRoots); 224 var mountedRootsSnapshot = cloneSet(mountedRoots); 225 var helpersByRootSnapshot = cloneMap(helpersByRoot); 226 failedRootsSnapshot.forEach(function (root) { 227 var helpers = helpersByRootSnapshot.get(root); 228 229 if (helpers === undefined) { 230 throw new Error('Could not find helpers for a root. This is a bug in React Refresh.'); 231 } 232 233 if (!failedRoots.has(root)) {// No longer failed. 234 } 235 236 if (rootElements === null) { 237 return; 238 } 239 240 if (!rootElements.has(root)) { 241 return; 242 } 243 244 var element = rootElements.get(root); 245 246 try { 247 helpers.scheduleRoot(root, element); 248 } catch (err) { 249 if (!didError) { 250 didError = true; 251 firstError = err; 252 } // Keep trying other roots. 253 254 } 255 }); 256 mountedRootsSnapshot.forEach(function (root) { 257 var helpers = helpersByRootSnapshot.get(root); 258 259 if (helpers === undefined) { 260 throw new Error('Could not find helpers for a root. This is a bug in React Refresh.'); 261 } 262 263 if (!mountedRoots.has(root)) {// No longer mounted. 264 } 265 266 try { 267 helpers.scheduleRefresh(root, update); 268 } catch (err) { 269 if (!didError) { 270 didError = true; 271 firstError = err; 272 } // Keep trying other roots. 273 274 } 275 }); 276 277 if (didError) { 278 throw firstError; 279 } 280 281 return update; 282 } finally { 283 isPerformingRefresh = false; 284 } 285} 286function register(type, id) { 287 { 288 if (type === null) { 289 return; 290 } 291 292 if (typeof type !== 'function' && typeof type !== 'object') { 293 return; 294 }
294 // This can happen in an edge case, e.g. if we register 295 // return value of a HOC but it returns a cached component. 296 // Ignore anything but the first registration for each type. 297 298 299 if (allFamiliesByType.has(type)) { 300 return; 301 } // Create family or remember to update it. 302 // None of this bookkeeping affects reconciliation 303 // until the first performReactRefresh() call above. 304 305 306 var family = allFamiliesByID.get(id); 307 308 if (family === undefined) { 309 family = { 310 current: type 311 }; 312 allFamiliesByID.set(id, family); 313 } else { 314 pendingUpdates.push([family, type]); 315 } 316 317 allFamiliesByType.set(type, family); // Visit inner types because we might not have registered them. 318 319 if (typeof type === 'object' && type !== null) { 320 switch (getProperty(type, '$$typeof')) { 321 case REACT_FORWARD_REF_TYPE: 322 register(type.render, id + '$render'); 323 break; 324 325 case REACT_MEMO_TYPE: 326 register(type.type, id + '$type'); 327 break; 328 } 329 } 330 } 331} 332function setSignature(type, key) { 333 var forceReset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; 334 var getCustomHooks = arguments.length > 3 ? arguments[3] : undefined; 335 336 { 337 if (!allSignaturesByType.has(type)) { 338 allSignaturesByType.set(type, { 339 forceReset: forceReset, 340 ownKey: key, 341 fullKey: null, 342 getCustomHooks: getCustomHooks || function () { 343 return []; 344 } 345 }); 346 } // Visit inner types because we might not have signed them. 347 348 349 if (typeof type === 'object' && type !== null) { 350 switch (getProperty(type, '$$typeof')) { 351 case REACT_FORWARD_REF_TYPE: 352 setSignature(type.render, key, forceReset, getCustomHooks); 353 break; 354 355 case REACT_MEMO_TYPE: 356 setSignature(type.type, key, forceReset, getCustomHooks); 357 break; 358 } 359 } 360 } 361} // This is lazily called during first render for a type. 362// It captures Hook list at that time so inline requires don't break comparisons. 363 364function collectCustomHooksForSignature(type) { 365 { 366 var signature = allSignaturesByType.get(type); 367 368 if (signature !== undefined) { 369 computeFullKey(signature); 370 } 371 } 372} 373function getFamilyByID(id) { 374 { 375 return allFamiliesByID.get(id); 376 } 377} 378function getFamilyByType(type) { 379 { 380 return allFamiliesByType.get(type); 381 } 382} 383function findAffectedHostInstances(families) { 384 { 385 var affectedInstances = new Set(); 386 mountedRoots.forEach(function (root) { 387 var helpers = helpersByRoot.get(root); 388 389 if (helpers === undefined) { 390 throw new Error('Could not find helpers for a root. This is a bug in React Refresh.'); 391 } 392 393 var instancesForRoot = helpers.findHostInstancesForRefresh(root, families); 394 instancesForRoot.forEach(function (inst) { 395 affectedInstances.add(inst); 396 }); 397 }); 398 return affectedInstances; 399 } 400} 401function injectIntoGlobalHook(globalObject) { 402 { 403 // For React Native, the global hook will be set up by require('react-devtools-core'). 404 // That code will run before us. So we need to monkeypatch functions on existing hook. 405 // For React Web, the global hook will be set up by the extension. 406 // This will also run before us. 407 var hook = globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__; 408 409 if (hook === undefined) { 410 // However, if there is no DevTools extension, we'll need to set up the global hook ourselves. 411 // Note that in this case it's important that renderer code runs *after* this method call. 412 // Otherwise, the renderer will think that there is no global hook, and won't do the injection. 413 var nextID = 0; 414 globalObject.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook = { 415 renderers: new Map(), 416 supportsFiber: true, 417 inject: function (injected) { 418 return nextID++; 419 }, 420 onScheduleFiberRoot: function (id, root, children) {}, 421 onCommitFiberRoot: function (id, root, maybePriorityLevel, didError) {}, 422 onCommitFiberUnmount: function () {} 423 }; 424 } 425 426 if (hook.isDisabled) { 427 // This isn't a real property on the hook, but it can be set to opt out 428 // of DevTools integration and associated warnings and logs. 429 // Using console['warn'] to evade Babel and ESLint 430 console['warn']('Something has shimmed the React DevTools global hook (__REACT_DEVTOOLS_GLOBAL_HOOK__). ' + 'Fast Refresh is not compatible with this shim and will be disabled.'); 431 return; 432 } // Here, we just want to get a reference to scheduleRefresh. 433 434 435 var oldInject = hook.inject; 436 437 hook.inject = function (injected) { 438 var id = oldInject.apply(this, arguments); 439 440 if (typeof injected.scheduleRefresh === 'function' && typeof injected.setRefreshHandler === 'function') { 441 // This version supports React Refresh. 442 helpersByRendererID.set(id, injected); 443 } 444 445 return id; 446 }; // Do the same for any already injected roots. 447 // This is useful if ReactDOM has already been initialized. 448 // https://github.com/facebook/react/issues/17626 449 450
451 hook.renderers.forEach(function (injected, id) { 452 if (typeof injected.scheduleRefresh === 'function' && typeof injected.setRefreshHandler === 'function') { 453 // This version supports React Refresh. 454 helpersByRendererID.set(id, injected); 455 } 456 }); // We also want to track currently mounted roots. 457 458 var oldOnCommitFiberRoot = hook.onCommitFiberRoot; 459 460 var oldOnScheduleFiberRoot = hook.onScheduleFiberRoot || function () {}; 461 462 hook.onScheduleFiberRoot = function (id, root, children) { 463 if (!isPerformingRefresh) { 464 // If it was intentionally scheduled, don't attempt to restore. 465 // This includes intentionally scheduled unmounts. 466 failedRoots.delete(root); 467 468 if (rootElements !== null) { 469 rootElements.set(root, children); 470 } 471 } 472 473 return oldOnScheduleFiberRoot.apply(this, arguments); 474 }; 475 476 hook.onCommitFiberRoot = function (id, root, maybePriorityLevel, didError) { 477 var helpers = helpersByRendererID.get(id); 478 479 if (helpers !== undefined) { 480 helpersByRoot.set(root, helpers); 481 var current = root.current; 482 var alternate = current.alternate; // We need to determine whether this root has just (un)mounted. 483 // This logic is copy-pasted from similar logic in the DevTools backend. 484 // If this breaks with some refactoring, you'll want to update DevTools too. 485 486 if (alternate !== null) { 487 var wasMounted = alternate.memoizedState != null && alternate.memoizedState.element != null && mountedRoots.has(root); 488 var isMounted = current.memoizedState != null && current.memoizedState.element != null; 489 490 if (!wasMounted && isMounted) { 491 // Mount a new root. 492 mountedRoots.add(root); 493 failedRoots.delete(root); 494 } else if (wasMounted && isMounted) ; else if (wasMounted && !isMounted) { 495 // Unmount an existing root. 496 mountedRoots.delete(root); 497 498 if (didError) { 499 // We'll remount it on future edits. 500 failedRoots.add(root); 501 } else { 502 helpersByRoot.delete(root); 503 } 504 } else if (!wasMounted && !isMounted) { 505 if (didError) { 506 // We'll remount it on future edits. 507 failedRoots.add(root); 508 } 509 } 510 } else { 511 // Mount a new root. 512 mountedRoots.add(root); 513 } 514 } // Always call the decorated DevTools hook. 515 516 517 return oldOnCommitFiberRoot.apply(this, arguments); 518 }; 519 } 520} 521function hasUnrecoverableErrors() { 522 // TODO: delete this after removing dependency in RN. 523 return false; 524} // Exposed for testing. 525 526function _getMountedRootCount() { 527 { 528 return mountedRoots.size; 529 } 530} // This is a wrapper over more primitive functions for setting signature. 531// Signatures let us decide whether the Hook order has changed on refresh. 532// 533// This function is intended to be used as a transform target, e.g.: 534// var _s = createSignatureFunctionForTransform() 535// 536// function Hello() { 537// const [foo, setFoo] = useState(0); 538// const value = useCustomHook(); 539// _s(); /* Call without arguments triggers collecting the custom Hook list. 540// * This doesn't happen during the module evaluation because we 541// * don't want to change the module order with inline requires. 542// * Next calls are noops. */ 543// return <h1>Hi</h1>; 544// } 545// 546// /* Call with arguments attaches the signature to the type: */ 547// _s( 548// Hello, 549// 'useState{[foo, setFoo]}(0)', 550// () => [useCustomHook], /* Lazy to avoid triggering inline requires */ 551// ); 552 553function createSignatureFunctionForTransform() { 554 { 555 var savedType; 556 var hasCustomHooks; 557 var didCollectHooks = false; 558 return function (type, key, forceReset, getCustomHooks) { 559 if (typeof key === 'string') { 560 // We're in the initial phase that associates signatures 561 // with the functions. Note this may be called multiple times 562 // in HOC chains like _s(hoc1(_s(hoc2(_s(actualFunction))))). 563 if (!savedType) { 564 // We're in the innermost call, so this is the actual type. 565 savedType = type; 566 hasCustomHooks = typeof getCustomHooks === 'function'; 567 } // Set the signature for all types (even wrappers!) in case 568 // they have no signatures of their own. This is to prevent 569 // problems like https://github.com/facebook/react/issues/20417. 570 571 572 if (type != null && (typeof type === 'function' || typeof type === 'object')) { 573 setSignature(type, key, forceReset, getCustomHooks); 574 } 575 576 return type; 577 } else { 578 // We're in the _s() call without arguments, which means 579 // this is the time to collect custom Hook signatures. 580 // Only do this once. This path is hot and runs *inside* every render! 581 if (!didCollectHooks && hasCustomHooks) { 582 didCollectHooks = true; 583 collectCustomHooksForSignature(savedType); 584 } 585 } 586 }; 587 } 588} 589function isLikelyComponentType(type) { 590 { 591 switch (typeof type) { 592 case 'function': 593 { 594 // First, deal with classes. 595 if (type.prototype != null) { 596 if (type.prototype.isReactComponent) { 597 // React class. 598 return true; 599 } 600 601 var ownNames = Object.getOwnPropertyNames(type.prototype); 602 603 if (ownNames.length > 1 || ownNames[0] !== 'constructor') { 604 // This looks like a class. 605 return false;
606 } // eslint-disable-next-line no-proto 607 608 609 if (type.prototype.__proto__ !== Object.prototype) { 610 // It has a superclass. 611 return false; 612 } // Pass through. 613 // This looks like a regular function with empty prototype. 614 615 } // For plain functions and arrows, use name as a heuristic. 616 617 618 var name = type.name || type.displayName; 619 return typeof name === 'string' && /^[A-Z]/.test(name); 620 } 621 622 case 'object': 623 { 624 if (type != null) { 625 switch (getProperty(type, '$$typeof')) { 626 case REACT_FORWARD_REF_TYPE: 627 case REACT_MEMO_TYPE: 628 // Definitely React components. 629 return true; 630 631 default: 632 return false; 633 } 634 } 635 636 return false; 637 } 638 639 default: 640 { 641 return false; 642 } 643 } 644 } 645} 646 647exports._getMountedRootCount = _getMountedRootCount; 648exports.collectCustomHooksForSignature = collectCustomHooksForSignature; 649exports.createSignatureFunctionForTransform = createSignatureFunctionForTransform; 650exports.findAffectedHostInstances = findAffectedHostInstances; 651exports.getFamilyByID = getFamilyByID; 652exports.getFamilyByType = getFamilyByType; 653exports.hasUnrecoverableErrors = hasUnrecoverableErrors; 654exports.injectIntoGlobalHook = injectIntoGlobalHook; 655exports.isLikelyComponentType = isLikelyComponentType; 656exports.performReactRefresh = performReactRefresh; 657exports.register = register; 658exports.setSignature = setSignature; 659 })(); 660} 661 662function debounce(fn, delay) { 663 let handle 664 return () => { 665 clearTimeout(handle) 666 handle = setTimeout(fn, delay) 667 } 668} 669 670/* eslint-disable no-undef */ 671const enqueueUpdate = debounce(exports.performReactRefresh, 16) 672 673// Taken from https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/lib/runtime/RefreshUtils.js#L141 674// This allows to resister components not detected by SWC like styled component 675function registerExportsForReactRefresh(filename, moduleExports) { 676 for (const key in moduleExports) { 677 if (key === '__esModule') continue 678 const exportValue = moduleExports[key] 679 if (exports.isLikelyComponentType(exportValue)) { 680 // 'export' is required to avoid key collision when renamed exports that 681 // shadow a local component name: https://github.com/vitejs/vite-plugin-react/issues/116 682 // The register function has an identity check to not register twice the same component, 683 // so this is safe to not used the same key here. 684 exports.register(exportValue, filename + ' export ' + key) 685 } 686 } 687} 688 689function validateRefreshBoundaryAndEnqueueUpdate(prevExports, nextExports) { 690 if (!predicateOnExport(prevExports, (key) => key in nextExports)) { 691 return 'Could not Fast Refresh (export removed)' 692 } 693 if (!predicateOnExport(nextExports, (key) => key in prevExports)) { 694 return 'Could not Fast Refresh (new export)' 695 } 696 697 let hasExports = false 698 const allExportsAreComponentsOrUnchanged = predicateOnExport( 699 nextExports, 700 (key, value) => { 701 hasExports = true 702 if (exports.isLikelyComponentType(value)) return true 703 return prevExports[key] === nextExports[key] 704 }, 705 ) 706 if (hasExports && allExportsAreComponentsOrUnchanged) { 707 enqueueUpdate() 708 } else { 709 return 'Could not Fast Refresh. Learn more at https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#consistent-components-exports' 710 } 711} 712 713function predicateOnExport(moduleExports, predicate) { 714 for (const key in moduleExports) { 715 if (key === '__esModule') continue 716 const desc = Object.getOwnPropertyDescriptor(moduleExports, key) 717 if (desc && desc.get) return false 718 if (!predicate(key, moduleExports[key])) return false 719 } 720 return true 721} 722 723// Hides vite-ignored dynamic import so that Vite can skip analysis if no other 724// dynamic import is present (https://github.com/vitejs/vite/pull/12732) 725function __hmr_import(module) { 726 return import(/* @vite-ignore */ __vite__injectQuery(module, 'import')) 727} 728 729exports.__hmr_import = __hmr_import 730exports.registerExportsForReactRefresh = registerExportsForReactRefresh 731exports.validateRefreshBoundaryAndEnqueueUpdate = 732 validateRefreshBoundaryAndEnqueueUpdate 733 734export default exports
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.