Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions client/intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,40 @@
* https://github.com/preactjs/prefresh/blob/018f5cc907629b82ffb201c32e948efe4b40098a/LICENSE
*/

var createRefreshSig = function () {
var status = 'begin';
var savedType;

return function (type, key, forceReset, getCustomHooks) {
if (!savedType) savedType = type;
status = self.__PREFRESH__.sign(
type || savedType,
key,
forceReset,
getCustomHooks,
status,
);
return type;
};
};

var noopRefreshReg = function () {};

// Components declared during render call $RefreshSig$ after their module
// factory has completed, so the hook must remain callable outside that scope.
if (typeof self.$RefreshSig$ !== 'function') {
self.$RefreshSig$ = createRefreshSig;
}
if (typeof self.$RefreshReg$ !== 'function') {
self.$RefreshReg$ = noopRefreshReg;
}

__webpack_require__.i.push(function (options) {
var originalFactory = options.factory;
options.factory = function (moduleObject, moduleExports, webpackRequire) {
var prevRefreshReg = self.$RefreshReg$;
var prevRefreshSig = self.$RefreshSig$;
self.$RefreshSig$ = function () {
var status = 'begin';
var savedType;

return function (type, key, forceReset, getCustomHooks) {
if (!savedType) savedType = type;
status = self.__PREFRESH__.sign(
type || savedType,
key,
forceReset,
getCustomHooks,
status,
);
return type;
};
};
self.$RefreshSig$ = createRefreshSig;
var reg = function (currentModuleId) {
self.$RefreshReg$ = function (type, id) {
self.__PREFRESH__.register(type, currentModuleId + ' ' + id);
Expand All @@ -38,8 +51,13 @@ __webpack_require__.i.push(function (options) {
try {
originalFactory.call(this, moduleObject, moduleExports, webpackRequire);
} finally {
self.$RefreshReg$ = prevRefreshReg;
self.$RefreshSig$ = prevRefreshSig;
// Restore the parent module hook, or detach registration at the root.
self.$RefreshReg$ =
typeof prevRefreshReg === 'function' ? prevRefreshReg : noopRefreshReg;
self.$RefreshSig$ =
typeof prevRefreshSig === 'function'
? prevRefreshSig
: createRefreshSig;
}
};
});
12 changes: 12 additions & 0 deletions test/hotCases/hook/useState_nested/__snapshots__/web/0.snap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Case useState_nested: Step 0

## Changed Files


## Asset Files
- Bundle: bundle.js

## Manifest


## Update
158 changes: 158 additions & 0 deletions test/hotCases/hook/useState_nested/__snapshots__/web/1.snap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Case useState_nested: Step 1

## Changed Files
- app.jsx

## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 4289

## Manifest

### main.LAST_HASH.hot-update.json

```json
{"c":["main"],"r":[],"m":[]}
```


## Update


### main.LAST_HASH.hot-update.js

#### Changed Modules
- ./app.jsx

#### Changed Runtime Modules
- webpack/runtime/get_full_hash

#### Changed Content
```js
"use strict";
self["rspackHotUpdate"]("main", {
"./app.jsx"(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
App: () => (App)
});
/* import */ var _swc_helpers_sliced_to_array__rspack_import_2 = __webpack_require__("<PNPM_INNER>/@swc/helpers/esm/_sliced_to_array.js");
/* import */ var react_jsx_dev_runtime__rspack_import_0 = __webpack_require__("<PNPM_INNER>/preact/compat/jsx-dev-runtime.js");
/* import */ var preact_hooks__rspack_import_1 = __webpack_require__("<PNPM_INNER>/preact/hooks/dist/hooks.module.js");
/* module decorator */ module = __webpack_require__.hmd(module);
/* provided dependency */ var __prefresh_utils__ = __webpack_require__("../../../../../../../client/prefresh.js")["default"];



function App() {
var _this = this;
var _s = $RefreshSig$();
var Nested = function Nested() {
_s();
var _useState = (0,_swc_helpers_sliced_to_array__rspack_import_2._)((0,preact_hooks__rspack_import_1.useState)('content 2'), 1), text = _useState[0];
return /*#__PURE__*/ (0,react_jsx_dev_runtime__rspack_import_0.jsxDEV)("span", {
children: text
}, void 0, false, {
fileName: "<TEST_ROOT>/test/js/temp/hot-snapshot/hotSnapshotCases-hotCases/hook/useState_nested/app.jsx",
lineNumber: 6,
columnNumber: 12
}, _this);
};
_s(Nested, "X+F/KlmfVDgKs4Hn0tEJDyERets=");
return /*#__PURE__*/ (0,react_jsx_dev_runtime__rspack_import_0.jsxDEV)(Nested, {}, void 0, false, {
fileName: "<TEST_ROOT>/test/js/temp/hot-snapshot/hotSnapshotCases-hotCases/hook/useState_nested/app.jsx",
lineNumber: 9,
columnNumber: 10
}, this);
}
_c = App;
var _c;
$RefreshReg$(_c, "App");

/**
* The following code is modified based on
* //https://github.com/preactjs/prefresh/blob/018f5cc907629b82ffb201c32e948efe4b40098a/packages/webpack/src/loader/runtime.js
*
* MIT Licensed
* Author JoviDeCroock
* Copyright (c) 2021-Present Preact Team
* https://github.com/preactjs/prefresh/blob/018f5cc907629b82ffb201c32e948efe4b40098a/LICENSE
*/

const isPrefreshComponent = __prefresh_utils__.shouldBind(module);

// `@vanilla-extract/webpack` does some custom preprocessing where
// `module.hot` is partially replaced. This leads to our injected
// code being executed although it shouldn't be:
//
// Intermediate result:
//
// if (true) { // <- inlined by intermediate compile step
// const previousHotModuleExports = module.hot.data && ...
// // Crash happens here ---^
//
// It crashes at that line because some intermediate compiler isn't
// running in hot mode, but the overall guard condition was compiled
// down to being truthy. By moving `module.hot` outside of the
// condition of the if-statement, it will be left as is.
const moduleHot = module.hot;

if (moduleHot) {
const currentExports = __prefresh_utils__.getExports(module);
const previousHotModuleExports =
moduleHot.data && moduleHot.data.moduleExports;

__prefresh_utils__.registerExports(currentExports, module.id);

if (isPrefreshComponent) {
if (previousHotModuleExports) {
try {
__prefresh_utils__.flush();
if (
typeof __prefresh_errors__ !== 'undefined' &&
__prefresh_errors__ &&
__prefresh_errors__.clearRuntimeErrors
) {
__prefresh_errors__.clearRuntimeErrors();
}
} catch (e) {
// Only available in newer webpack versions.
if (moduleHot.invalidate) {
moduleHot.invalidate();
} else {
self.location.reload();
}
}
}

moduleHot.dispose(data => {
data.moduleExports = __prefresh_utils__.getExports(module);
});

moduleHot.accept(function errorRecovery(error) {
if (
typeof __prefresh_errors__ !== 'undefined' &&
__prefresh_errors__ &&
__prefresh_errors__.handleRuntimeError
) {
__prefresh_errors__.handleRuntimeError(error);
}

__webpack_require__.c[module.id].hot.accept(errorRecovery);
});
}
}


},

},function(__webpack_require__) {
// webpack/runtime/get_full_hash
(() => {
__webpack_require__.h = () => ("CURRENT_HASH")
})();

}
);
```
Loading
Loading