(component, options)
| 93 | * @returns {Exports} |
| 94 | */ |
| 95 | export function hydrate(component, options) { |
| 96 | init_operations(); |
| 97 | options.intro = options.intro ?? false; |
| 98 | const target = options.target; |
| 99 | const was_hydrating = hydrating; |
| 100 | const previous_hydrate_node = hydrate_node; |
| 101 | |
| 102 | try { |
| 103 | var anchor = get_first_child(target); |
| 104 | |
| 105 | while ( |
| 106 | anchor && |
| 107 | (anchor.nodeType !== COMMENT_NODE || /** @type {Comment} */ (anchor).data !== HYDRATION_START) |
| 108 | ) { |
| 109 | anchor = get_next_sibling(anchor); |
| 110 | } |
| 111 | |
| 112 | if (!anchor) { |
| 113 | throw HYDRATION_ERROR; |
| 114 | } |
| 115 | |
| 116 | set_hydrating(true); |
| 117 | set_hydrate_node(/** @type {Comment} */ (anchor)); |
| 118 | |
| 119 | const instance = _mount(component, { ...options, anchor }); |
| 120 | |
| 121 | set_hydrating(false); |
| 122 | |
| 123 | return /** @type {Exports} */ (instance); |
| 124 | } catch (error) { |
| 125 | // re-throw Svelte errors - they are certainly not related to hydration |
| 126 | if ( |
| 127 | error instanceof Error && |
| 128 | error.message.split('\n').some((line) => line.startsWith('https://svelte.dev/e/')) |
| 129 | ) { |
| 130 | throw error; |
| 131 | } |
| 132 | if (error !== HYDRATION_ERROR) { |
| 133 | // eslint-disable-next-line no-console |
| 134 | console.warn('Failed to hydrate: ', error); |
| 135 | } |
| 136 | |
| 137 | if (options.recover === false) { |
| 138 | e.hydration_failed(); |
| 139 | } |
| 140 | |
| 141 | // If an error occurred above, the operations might not yet have been initialised. |
| 142 | init_operations(); |
| 143 | clear_text_content(target); |
| 144 | |
| 145 | set_hydrating(false); |
| 146 | return mount(component, options); |
| 147 | } finally { |
| 148 | set_hydrating(was_hydrating); |
| 149 | set_hydrate_node(previous_hydrate_node); |
| 150 | } |
| 151 | } |
| 152 |
nothing calls this directly
no test coverage detected