File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1+ import waitFor from 'p-wait-for'
2+
13import { GROUPS } from './config'
24import { applyGroups } from './shared'
35
6+ async function waitRuntimeReady ( ) {
7+ const getQueue = ( ) => ( window . webpackChunk_figma_web_bundler ||= [ ] )
8+
9+ await waitFor ( ( ) => {
10+ const queue = getQueue ( )
11+ return typeof queue . push === 'function' && queue . push !== Array . prototype . push
12+ } )
13+ }
14+
415async function rewriteScript ( ) {
516 const current = document . currentScript as HTMLScriptElement
617 const src = current ?. src
@@ -29,6 +40,8 @@ async function rewriteScript() {
2940
3041 const content = afterRules . replaceAll ( 'delete window.figma' , 'window.figma = undefined' )
3142
43+ await waitRuntimeReady ( )
44+
3245 Object . defineProperty ( document , 'currentScript' , {
3346 configurable : true ,
3447 get ( ) {
@@ -41,7 +54,11 @@ async function rewriteScript() {
4154 console . error ( e )
4255 replaceScript ( `${ src } ?fallback` )
4356 } finally {
44- Object . defineProperty ( document , 'currentScript' , desc as PropertyDescriptor )
57+ if ( desc ) {
58+ Object . defineProperty ( document , 'currentScript' , desc )
59+ } else {
60+ delete ( document as any ) . currentScript
61+ }
4562 }
4663}
4764
Original file line number Diff line number Diff line change 11interface Window {
22 figma : PluginAPI
3+ webpackChunk_figma_web_bundler : any [ ] & { push : ( ...args : any [ ] ) => any }
34}
You can’t perform that action at this time.
0 commit comments