File tree Expand file tree Collapse file tree 2 files changed +30
-20
lines changed
Expand file tree Collapse file tree 2 files changed +30
-20
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
22
3- const transactionCtx = ( ( ) => {
4- try {
5- const runtimeRequire = eval ( 'require' ) ;
6- return runtimeRequire ( '@strapi/database/dist/transaction-context' ) . transactionCtx ;
7- } catch ( error ) {
8- console . warn ( '[strapi-plugin-io] Unable to access transaction context:' , error . message ) ;
9- return null ;
3+ // Lazy-load transaction context to avoid bundling issues
4+ let transactionCtx = null ;
5+ function getTransactionCtx ( ) {
6+ if ( ! transactionCtx ) {
7+ try {
8+ transactionCtx = require ( '@strapi/database/dist/transaction-context' ) . transactionCtx ;
9+ } catch ( error ) {
10+ console . warn ( '[strapi-plugin-io] Unable to access transaction context:' , error . message ) ;
11+ transactionCtx = { get : ( ) => null , onCommit : ( ) => { } } ; // Fallback noop
12+ }
1013 }
11- } ) ( ) ;
14+ return transactionCtx ;
15+ }
1216
1317const { pluginId } = require ( '../utils/pluginId' ) ;
1418
@@ -18,8 +22,9 @@ const { pluginId } = require('../utils/pluginId');
1822 */
1923function scheduleAfterTransaction ( callback , delay = 0 ) {
2024 const runner = ( ) => setTimeout ( callback , delay ) ;
21- if ( transactionCtx ?. get ( ) ) {
22- transactionCtx . onCommit ( runner ) ;
25+ const ctx = getTransactionCtx ( ) ;
26+ if ( ctx . get ( ) ) {
27+ ctx . onCommit ( runner ) ;
2328 } else {
2429 runner ( ) ;
2530 }
Original file line number Diff line number Diff line change 11'use strict' ;
22
3- const transactionCtx = ( ( ) => {
4- try {
5- const runtimeRequire = eval ( 'require' ) ;
6- return runtimeRequire ( '@strapi/database/dist/transaction-context' ) . transactionCtx ;
7- } catch ( error ) {
8- console . warn ( '[strapi-plugin-io] Unable to access transaction context:' , error . message ) ;
9- return null ;
3+ // Lazy-load transaction context to avoid bundling issues
4+ let transactionCtx = null ;
5+ function getTransactionCtx ( ) {
6+ if ( ! transactionCtx ) {
7+ try {
8+ transactionCtx = require ( '@strapi/database/dist/transaction-context' ) . transactionCtx ;
9+ } catch ( error ) {
10+ console . warn ( '[strapi-plugin-io] Unable to access transaction context:' , error . message ) ;
11+ transactionCtx = { get : ( ) => null , onCommit : ( ) => { } } ; // Fallback noop
12+ }
1013 }
11- } ) ( ) ;
14+ return transactionCtx ;
15+ }
1216
1317function scheduleAfterTransaction ( callback , delay = 0 ) {
1418 const runner = ( ) => setTimeout ( callback , delay ) ;
15- if ( transactionCtx ?. get ( ) ) {
16- transactionCtx . onCommit ( runner ) ;
19+ const ctx = getTransactionCtx ( ) ;
20+ if ( ctx . get ( ) ) {
21+ ctx . onCommit ( runner ) ;
1722 } else {
1823 runner ( ) ;
1924 }
You can’t perform that action at this time.
0 commit comments