Skip to content

Commit

Permalink
feat: support queueMicroTask on the server side of SSR (#3873)
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder authored Oct 31, 2024
1 parent d594eb0 commit 62926c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions e2e/cases/server/ssr/src/assert.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function assertQueueMicroTask() {
if (typeof queueMicrotask !== 'function') {
throw Error('not support queueMicrotask in this environment');
}
}

export function assert() {
assertQueueMicroTask();
}
4 changes: 4 additions & 0 deletions e2e/cases/server/ssr/src/index.server.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import App from './App';
import { assert } from './assert.server';

// test dynamic import
import('./test');

// assert environment
assert();

export function render() {
return ReactDOMServer.renderToString(
<React.StrictMode>
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/server/runner/cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class CommonJsRunner extends BasicRunner {
return timeout;
}) as typeof setTimeout,
clearTimeout: clearTimeout,
queueMicrotask,
};
}

Expand All @@ -43,6 +44,7 @@ export class CommonJsRunner extends BasicRunner {
});
return m;
},
queueMicrotask,
};
return baseModuleScope;
}
Expand Down

1 comment on commit 62926c1

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
plugins ✅ success
rspress ✅ success
rslib ✅ success
examples ✅ success

Please sign in to comment.