Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to specify a scope for text/partytown scripts #624

Closed
wants to merge 5 commits into from

Conversation

aaa123eee
Copy link
Contributor

@aaa123eee aaa123eee commented Sep 11, 2024

What is it?

  • Feature / enhancement
  • Bug
  • Docs / tests

Description

We have our custom "text/partytown" scripts added to the document which meant to be executed only in the worker scope.

If the fallback happens, we have to check an execution scope to avoid errors,
like typeof WorkerGlobalScope === 'undefined'

I suggest more elegant way of settling a scope for a script

<script type="text/partytown"  ptScope="worker" src="/worker-custom-logic.js"></script>

Checklist:

  • My code follows the developer guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • Added new tests to cover the fix / functionality

Copy link

vercel bot commented Sep 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
partytown ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 11, 2024 9:24pm

@gioboa
Copy link
Member

gioboa commented Nov 18, 2024

@aaa123eee so if I understand correctly, you would like a discriminant to define which scripts to re-execute in case of fallback and which not, right?

@gioboa gioboa added the waiting for an answer Further information is requested label Nov 18, 2024
@aaa123eee
Copy link
Contributor Author

@aaa123eee so if I understand correctly, you would like a discriminant to define which scripts to re-execute in case of fallback and which not, right?

generally yes

currently fallback logic takes all scripts to the main thread regardless a need to do so

@aaa123eee aaa123eee closed this by deleting the head repository Nov 18, 2024
@gioboa
Copy link
Member

gioboa commented Nov 18, 2024

Can you share some examples please?

@aaa123eee
Copy link
Contributor Author

ouch, seems that I forgot about this one and removed the repo, I will redo it

Can you share some examples please?

@gioboa here are usages examples:

  • We have custom storage where we keep data to reduce communication with worker. We create a type="text/partytown" script to handle it from the worker side. Once fallback logic kicks in, we have unnecessary code in the main thread
  • We found data loss in our tracking because of delays with a busy worker thread. We create a logic that keeps control over tracking events and save data until it is safely sent. Again, there's a logic that only belongs to the worker and should not hit main thread

@gioboa
Copy link
Member

gioboa commented Nov 19, 2024

I see, thanks for your explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for an answer Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants