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

[nextjs]: Fix typings of window. More strict typing for window #367

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ssbarbee
Copy link

Add example checklist

  • Any commit does not contain the charting library's code
  • The example is self-sufficient and contains only necessary files/changes

Bug fix checklist

  • Any commit does not contain the charting library's code

@ssbarbee
Copy link
Author

@SlicedSilver do you mind reviewing this PR?

@SlicedSilver
Copy link
Contributor

I think it would be better if we updated the example to import the datafeed class directly instead of loading it via a <script> tag which pollutes the global window scope.

I haven't tested this, but looking at the existing syntax I would expect something like this to work:

import { UDFCompatibleDatafeed } from "@/public/static/datafeeds/udf/src/udf-compatible-datafeed";

@ssbarbee
Copy link
Author

I think it would be better if we updated the example to import the datafeed class directly instead of loading it via a <script> tag which pollutes the global window scope.

I haven't tested this, but looking at the existing syntax I would expect something like this to work:

import { UDFCompatibleDatafeed } from "@/public/static/datafeeds/udf/src/udf-compatible-datafeed";

Do you mind explaining to me about the <script> tag? I don't introduce any script tags.

What you propose tries to dig the type from public folder. Isn't it better approach that we type it on our own until it is available via index.d.ts from "@/public/static/charting_library", like every other type export?

Cheers!

@SlicedSilver
Copy link
Contributor

Do you mind explaining to me about the <script> tag? I don't introduce any script tags.

The script tag is defined here:

<Script
src="/static/datafeeds/udf/dist/bundle.js"
strategy="lazyOnload"
onReady={() => {
setIsScriptReady(true);
}}
/>

This means that the datafeed is loaded via a script tag (IIFE) and is added as a global variable to the window.

An alternative would be to remove this script tag and rather load the datafeed class directly via an import statement.

@ssbarbee
Copy link
Author

@SlicedSilver I still see this PR not merged. I opened it because I thought it brought some value to the codebase. If not lets close it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants