question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

global function defined in one partytown script is not accessible to other partytown scripts

See original GitHub issue

Please check this sandbox : https://vpxcwd.csb.app/ ( https://codesandbox.io/s/partytown-global-functions-vpxcwd )

sandbox uses latest Partytown version 0.5.0

In this sandbox, there are two scripts foo.js and bar.js both are partytown scripts and so both runs in same worker thread.

foo.js defines a function foo.
bar.js tries to use function foo

Expectation: bar.js should be able to use function foo

Problem: bar.js is not able to use function foo and throws error

image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
adamdbradleycommented, Mar 16, 2022

There currently is a config called globalFn and it’s documented only in the types for now: https://github.com/BuilderIO/partytown/blob/072ac28bc17aedb6b97d01ee2c99013daa1064e7/src/lib/types.ts#L390-L398

Still trying to think of the best way to tackle this problem without having to add another config, which would rarely be obvious.

1reaction
MananTankcommented, Jul 23, 2022

@garethweaver Thanks for the update!

Just to let you know that the original issue I mentioned in this issue is fixable, I actually created my own library (Proxytown) that works similar to Partytown where I fixed this issue.

In that library one script running in worker can access other script’s globally defined variables or even main thread’s global variables without having any kind of configuration.

Here it is : https://github.com/MananTank/proxytown

I created this library 3 months ago and completely forgot to post it here 😅, I thought I would post it here once it’s fully tested - But I never got the time to do that.

Anyway,

Here is an example sandbox using this library: https://7ebxo6.csb.app/ ( https://codesandbox.io/s/7ebxo6?file=/index.html )

@adamdbradley May be you can check out this library (proxytown) and see if this is something you guys can implement in partytown

There are some bugs when Symbols are used as keys. But for the most part, Everything seems to work with that architecture. Library is also pretty lean and I did not have to mock any WEB/DOM APIs.

Hopefully, I will get some free time in future to properly test this library and release beta version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manan Tank on Twitter: "created issue : https://t.co/v2U5pXnixh ...
It seems like global function defined in one partytown script is not accessible to other partytown scripts https://vpxcwd.csb.app sandbox: ...
Read more >
Use your third-party scripts without the performance hit with ...
Partytown is a lazy-loaded library to help relocate resource intensive scripts into a web worker, and off of the main thread. Its goal...
Read more >
Partytown - HackMD
Partytown is a 5kb library to help relocate resource intensive scripts into ... From Third-Party Scripts; Goals; Web Workers; Browser Window And DOM...
Read more >
Partytown Scripts - Builder.io
Add the type="text/partytown" attribute to each individual third-party script to run from a web worker. Note that each script is opt-in, meaning that...
Read more >
Sandboxing with Partytown - Weston Ruter
Partytown is a “library to help relocate resource intensive ... used by amp-script to ensure that third-party scripts do not violate AMP's ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found